add ConvertI64FormatString

This commit is contained in:
Glenn Maynard
2007-02-21 05:31:51 +00:00
parent 8f29e21c9f
commit 73cb935f7e
2 changed files with 42 additions and 0 deletions
+41
View File
@@ -361,6 +361,47 @@ RString vssprintf( const char *szFormat, va_list argList )
return sStr;
}
/* Windows uses %I64i to format a 64-bit int, instead of %lli. Convert "a b %lli %-3llu c d"
* to "a b %I64 %-3I64u c d". This assumes a well-formed format string; invalid format strings
* should not crash, but the results are undefined. */
#if defined(WIN32)
RString ConvertI64FormatString( const RString &sStr )
{
RString sRet;
sRet.reserve( sStr.size() + 16 );
size_t iOffset = 0;
while( iOffset < sStr.size() )
{
size_t iPercent = sStr.find( '%', iOffset );
if( iPercent != sStr.npos )
{
sRet.append( sStr, iOffset, iPercent - iOffset );
iOffset = iPercent;
}
size_t iEnd = sStr.find_first_of( "diouxXeEfFgGaAcsCSpnm%", iOffset + 1 );
if( iEnd != sStr.npos && iEnd - iPercent >= 3 && iPercent > 2 && sStr[iEnd-2] == 'l' && sStr[iEnd-1] == 'l' )
{
sRet.append( sStr, iPercent, iEnd - iPercent - 2 ); // %
sRet.append( "I64" ); // %I64
sRet.append( sStr, iEnd, 1 ); // %I64i
iOffset = iEnd + 1;
}
else
{
if( iEnd == sStr.npos )
iEnd = sStr.size() - 1;
sRet.append( sStr, iOffset, iEnd - iOffset + 1 );
iOffset = iEnd + 1;
}
}
return sRet;
}
#else
RString ConvertI64FormatString( const RString &sStr ) { return sStr; }
#endif
/* ISO-639-1 codes: http://www.loc.gov/standards/iso639-2/langcodes.html
* native forms: http://people.w3.org/rishida/names/languages.html
* We don't use 3-letter codes, so we don't bother supporting them. */
+1
View File
@@ -351,6 +351,7 @@ struct tm GetLocalTime();
RString ssprintf( const char *fmt, ...) PRINTF(1,2);
RString vssprintf( const char *fmt, va_list argList );
RString ConvertI64FormatString( const RString &sStr );
/*
* Splits a Path into 4 parts (Directory, Drive, Filename, Extention). Supports UNC path names.