Bug 592009. Fix AppendPrintf to support more than 31 characters. r=bsmedberg

We can use vsmprintf to have the formatting code do the allocation for us.
This commit is contained in:
Jeff Muizelaar 2011-08-25 10:43:49 -04:00
parent 5ccd779f2f
commit 10f647ec1a
2 changed files with 22 additions and 10 deletions

View File

@ -387,35 +387,34 @@ class nsTSubstring_CharT
void AppendASCII( const char* data, size_type length = size_type(-1) ) { ReplaceASCII(mLength, 0, data, length); }
// AppendPrintf truncates output to 31 ASCII characters
void AppendPrintf( const char* format, ... );
void AppendInt( PRInt32 aInteger )
{ AppendPrintf( "%d", aInteger ); }
{ AppendPrintf31( "%d", aInteger ); }
void AppendInt( PRInt32 aInteger, int aRadix )
{
const char *fmt = aRadix == 10 ? "%d" : aRadix == 8 ? "%o" : "%x";
AppendPrintf( fmt, aInteger );
AppendPrintf31( fmt, aInteger );
}
void AppendInt( PRUint32 aInteger )
{ AppendPrintf( "%u", aInteger ); }
{ AppendPrintf31( "%u", aInteger ); }
void AppendInt( PRUint32 aInteger, int aRadix )
{
const char *fmt = aRadix == 10 ? "%u" : aRadix == 8 ? "%o" : "%x";
AppendPrintf( fmt, aInteger );
AppendPrintf31( fmt, aInteger );
}
void AppendInt( PRInt64 aInteger )
{ AppendPrintf( "%lld", aInteger ); }
{ AppendPrintf31( "%lld", aInteger ); }
void AppendInt( PRInt64 aInteger, int aRadix )
{
const char *fmt = aRadix == 10 ? "%lld" : aRadix == 8 ? "%llo" : "%llx";
AppendPrintf( fmt, aInteger );
AppendPrintf31( fmt, aInteger );
}
void AppendInt( PRUint64 aInteger )
{ AppendPrintf( "%llu", aInteger ); }
{ AppendPrintf31( "%llu", aInteger ); }
void AppendInt( PRUint64 aInteger, int aRadix )
{
const char *fmt = aRadix == 10 ? "%llu" : aRadix == 8 ? "%llo" : "%llx";
AppendPrintf( fmt, aInteger );
AppendPrintf31( fmt, aInteger );
}
/**
@ -427,6 +426,8 @@ class nsTSubstring_CharT
{ DoAppendFloat(aFloat, 15); }
private:
void NS_FASTCALL DoAppendFloat( double aFloat, int digits );
// AppendPrintf31 truncates output to 31 ASCII characters
void AppendPrintf31( const char* format, ... );
public:
// AppendLiteral must ONLY be applied to an actual literal string.

View File

@ -735,7 +735,7 @@ nsTSubstring_CharT::StripChars( const char_type* aChars, PRUint32 aOffset )
mLength = to - mData;
}
void nsTSubstring_CharT::AppendPrintf( const char* format, ...)
void nsTSubstring_CharT::AppendPrintf31( const char* format, ...)
{
char buf[32];
va_list ap;
@ -745,6 +745,17 @@ void nsTSubstring_CharT::AppendPrintf( const char* format, ...)
va_end(ap);
}
void nsTSubstring_CharT::AppendPrintf( const char* format, ...)
{
char *buf;
va_list ap;
va_start(ap, format);
buf = PR_vsmprintf(format, ap);
AppendASCII(buf);
PR_smprintf_free(buf);
va_end(ap);
}
/* hack to make sure we define Modified_cnvtf only once */
#ifdef CharT_is_PRUnichar