[Kstars-devel] kdeedu/kstars/kstars [POSSIBLY UNSAFE]
Jason Harris
kstars at 30doradus.org
Thu Sep 25 07:53:10 CEST 2003
CVS commit by harris:
dmsBoxes now pad their fields with a leading "0" when the degree/minute/second values are less than 10.
Sorry about the sprintf(), but it's by far the easiest way to prefix a "0" on a two-digit integer field when the value is less than 10. I mean, it's the difference between:
QString s = QString().sprintf( "%02d %02d %02d", v1, v2, v3 );
and:
QString s1 = QString( "%1" ).arg( v1, 2 );
if ( v1 < 10 ) { s1 = QString( "0%1" ).arg( v1, 1 ); }
QString s2 = QString( "%1" ).arg( v2, 2 );
if ( v2 < 10 ) { s2 = QString( "0%1" ).arg( v2, 1 ); }
QString s3 = QString( "%1" ).arg( v3, 2 );
if ( v3 < 10 ) { s3 = QString( "0%1" ).arg( v3, 1 ); }
QString s = QString( "%1 %2 %3" ).arg( s1 ).arg( s2 ).arg( s3 );
IOW, a no-brainer. If anyone knows a better way, let me know. :)
CCMAIL: kstars-devel at kde.org
M +2 -5 dmsbox.cpp 1.23 [POSSIBLY UNSAFE: printf]
--- kdeedu/kstars/kstars/dmsbox.cpp #1.22:1.23
@@ -44,6 +44,5 @@ void dmsBox::showInDegrees (dms d)
{
double seconds = d.arcsec() + d.marcsec()/1000.;
-
- setDMS ( QString("%1 %2 %3").arg(d.degree(),2).arg(d.arcmin(),2).arg(seconds,6,'f',2) );
+ setDMS( QString().sprintf( "%02d %02d %05.2f", d.degree(), d.arcmin(), seconds ) );
}
@@ -52,7 +51,5 @@ void dmsBox::showInHours (dms d)
{
double seconds = d.second() + d.msecond()/1000.;
-
- setDMS ( QString("%1 %2 %3").arg(d.hour(),2).arg(d.minute(),2).arg(seconds,6,'f',3) );
-
+ setDMS( QString().sprintf( "%02d %02d %05.2f", d.hour(), d.minute(), seconds ) );
}
More information about the Kstars-devel
mailing list