Fixing bug 243484. Adding 'count' out params to ToNewUTF8String() and UTF8ToNewUnicode() that tells the caller how many units (8 or 16 bit) that was returned. r=dbaron@dbaron.org, sr=darin@meer.net

This commit is contained in:
jst%mozilla.jstenback.com 2004-05-13 17:45:03 +00:00
Родитель 2683530f86
Коммит ccbb6dceef
2 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -126,10 +126,11 @@ NS_COM char* ToNewCString( const nsACString& aSource );
* contains embedded nulls.
*
* @param aSource a UTF-16 string (made of PRUnichar's)
* @param aUTF8Count the number of 8-bit units that was returned
* @return a new |char| buffer you must free with |nsMemory::Free|.
*/
NS_COM char* ToNewUTF8String( const nsAString& aSource );
NS_COM char* ToNewUTF8String( const nsAString& aSource, PRUint32 *aUTF8Count = nsnull );
/**
@ -171,10 +172,11 @@ NS_COM PRUnichar* ToNewUnicode( const nsACString& aSource );
* may not help you if |aSource| contains embedded nulls.
*
* @param aSource an 8-bit wide string, UTF-8 encoded
* @param aUTF16Count the number of 16-bit units that was returned
* @return a new |PRUnichar| buffer you must free with |nsMemory::Free|.
* (UTF-16 encoded)
*/
NS_COM PRUnichar* UTF8ToNewUnicode( const nsACString& aSource );
NS_COM PRUnichar* UTF8ToNewUnicode( const nsACString& aSource, PRUint32 *aUTF16Count = nsnull );
/**
* Copies |aLength| 16-bit code units from the start of |aSource| to the

Просмотреть файл

@ -325,13 +325,16 @@ ToNewCString( const nsAString& aSource )
NS_COM
char*
ToNewUTF8String( const nsAString& aSource )
ToNewUTF8String( const nsAString& aSource, PRUint32 *aUTF8Count )
{
nsAString::const_iterator start, end;
CalculateUTF8Size calculator;
copy_string(aSource.BeginReading(start), aSource.EndReading(end),
calculator);
if (aUTF8Count)
*aUTF8Count = calculator.Size();
char *result = NS_STATIC_CAST(char*,
nsMemory::Alloc(calculator.Size() + 1));
@ -385,13 +388,16 @@ ToNewUnicode( const nsACString& aSource )
NS_COM
PRUnichar*
UTF8ToNewUnicode( const nsACString& aSource )
UTF8ToNewUnicode( const nsACString& aSource, PRUint32 *aUTF16Count )
{
nsACString::const_iterator start, end;
CalculateUTF8Length calculator;
copy_string(aSource.BeginReading(start), aSource.EndReading(end),
calculator);
if (aUTF16Count)
*aUTF16Count = calculator.Length();
PRUnichar *result = NS_STATIC_CAST(PRUnichar*,
nsMemory::Alloc(sizeof(PRUnichar) * (calculator.Length() + 1)));