From 342740557a4d0c8c982b1984967a2dd50f01c5b9 Mon Sep 17 00:00:00 2001 From: "peter%propagandism.org" Date: Tue, 23 Dec 2003 09:56:23 +0000 Subject: [PATCH] Patch for bug 209699 (convert some consumers over to CopyUTF8toUTF16 / CopyUTF16toUTF8). r=jshin, sr=jst. --- xpcom/ds/nsStringEnumerator.cpp | 2 +- xpcom/ds/nsVariant.cpp | 86 +++++++++++++------------------ xpcom/io/nsLocalFileOSX.cpp | 4 +- xpcom/io/nsNativeCharsetUtils.cpp | 4 +- 4 files changed, 40 insertions(+), 56 deletions(-) diff --git a/xpcom/ds/nsStringEnumerator.cpp b/xpcom/ds/nsStringEnumerator.cpp index d7e6fb90d77..ecf95965d20 100644 --- a/xpcom/ds/nsStringEnumerator.cpp +++ b/xpcom/ds/nsStringEnumerator.cpp @@ -159,7 +159,7 @@ nsStringEnumerator::GetNext(nsAString& aResult) if (mIsUnicode) aResult = *mArray->StringAt(mIndex++); else - aResult = NS_ConvertUTF8toUCS2(*mCArray->CStringAt(mIndex++)); + CopyUTF8toUTF16(*mCArray->CStringAt(mIndex++), aResult); return NS_OK; } diff --git a/xpcom/ds/nsVariant.cpp b/xpcom/ds/nsVariant.cpp index e34a1dceec2..f6aa032a1c7 100644 --- a/xpcom/ds/nsVariant.cpp +++ b/xpcom/ds/nsVariant.cpp @@ -836,9 +836,6 @@ static nsresult ToString(const nsDiscriminatedUnion& data, nsVariant::ConvertToAString(const nsDiscriminatedUnion& data, nsAString & _retval) { - nsCAutoString tempCString; - nsresult rv; - switch(data.mType) { case nsIDataType::VTYPE_ASTRING: @@ -849,13 +846,10 @@ nsVariant::ConvertToAString(const nsDiscriminatedUnion& data, CopyASCIItoUCS2(*data.u.mCStringValue, _retval); return NS_OK; case nsIDataType::VTYPE_UTF8STRING: - // XXX This is an extra copy that should be avoided - // once Jag lands support for UTF8String and associated - // conversion methods. - _retval.Assign(NS_ConvertUTF8toUCS2(*data.u.mUTF8StringValue)); + CopyUTF8toUTF16(*data.u.mUTF8StringValue, _retval); return NS_OK; case nsIDataType::VTYPE_CHAR_STR: - CopyASCIItoUCS2(nsDependentCString(data.u.str.mStringValue), _retval); + CopyASCIItoUTF16(data.u.str.mStringValue, _retval); return NS_OK; case nsIDataType::VTYPE_WCHAR_STR: _retval.Assign(data.u.wstr.mWStringValue); @@ -872,20 +866,21 @@ nsVariant::ConvertToAString(const nsDiscriminatedUnion& data, _retval.Assign(data.u.mWCharValue); return NS_OK; default: - rv = ToString(data, tempCString); + { + nsCAutoString tempCString; + nsresult rv = ToString(data, tempCString); if(NS_FAILED(rv)) return rv; - CopyASCIItoUCS2(tempCString, _retval); + CopyASCIItoUTF16(tempCString, _retval); return NS_OK; } + } } /* static */ nsresult nsVariant::ConvertToACString(const nsDiscriminatedUnion& data, nsACString & _retval) { - nsresult rv; - switch(data.mType) { case nsIDataType::VTYPE_ASTRING: @@ -923,10 +918,7 @@ nsVariant::ConvertToACString(const nsDiscriminatedUnion& data, return NS_OK; } default: - rv = ToString(data, _retval); - if(NS_FAILED(rv)) - return rv; - return NS_OK; + return ToString(data, _retval); } } @@ -934,68 +926,60 @@ nsVariant::ConvertToACString(const nsDiscriminatedUnion& data, nsVariant::ConvertToAUTF8String(const nsDiscriminatedUnion& data, nsAUTF8String & _retval) { - nsCAutoString tempCString; - nsresult rv; - switch(data.mType) { case nsIDataType::VTYPE_ASTRING: case nsIDataType::VTYPE_DOMSTRING: - // XXX Extra copy. Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8(*data.u.mAStringValue)); + CopyUTF16toUTF8(*data.u.mAStringValue, _retval); return NS_OK; case nsIDataType::VTYPE_CSTRING: - // XXX Extra copy and conversion. - // Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - NS_ConvertASCIItoUCS2(*data.u.mCStringValue))); + // XXX Extra copy, can be removed if we're sure CSTRING can + // only contain ASCII. + CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(*data.u.mCStringValue), + _retval); return NS_OK; case nsIDataType::VTYPE_UTF8STRING: _retval.Assign(*data.u.mUTF8StringValue); return NS_OK; case nsIDataType::VTYPE_CHAR_STR: - // XXX Extra copy and conversion. - // Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - NS_ConvertASCIItoUCS2( - nsDependentCString(data.u.str.mStringValue)))); + // XXX Extra copy, can be removed if we're sure CHAR_STR can + // only contain ASCII. + CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(data.u.str.mStringValue), + _retval); return NS_OK; case nsIDataType::VTYPE_WCHAR_STR: - // XXX Extra copy. Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - nsDependentString(data.u.wstr.mWStringValue))); + CopyUTF16toUTF8(data.u.wstr.mWStringValue, _retval); return NS_OK; case nsIDataType::VTYPE_STRING_SIZE_IS: - // XXX Extra copy and conversion. - // Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - NS_ConvertASCIItoUCS2( - nsDependentCString(data.u.str.mStringValue, - data.u.str.mStringLength)))); + // XXX Extra copy, can be removed if we're sure CHAR_STR can + // only contain ASCII. + CopyUTF16toUTF8(NS_ConvertASCIItoUTF16( + nsDependentCString(data.u.str.mStringValue, + data.u.str.mStringLength)), _retval); return NS_OK; case nsIDataType::VTYPE_WSTRING_SIZE_IS: - // XXX Extra copy. Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - nsDependentString(data.u.wstr.mWStringValue, - data.u.wstr.mWStringLength))); + CopyUTF16toUTF8(nsDependentString(data.u.wstr.mWStringValue, + data.u.wstr.mWStringLength), + _retval); return NS_OK; case nsIDataType::VTYPE_WCHAR: { - // XXX Extra copies. Jag will fix when he lands UTF8String - nsAutoString tempString(data.u.mWCharValue); - _retval.Assign(NS_ConvertUCS2toUTF8(tempString)); + const PRUnichar* str = &data.u.mWCharValue; + CopyUTF16toUTF8(Substring(str, str), _retval); return NS_OK; } default: - rv = ToString(data, tempCString); + { + nsCAutoString tempCString; + nsresult rv = ToString(data, tempCString); if(NS_FAILED(rv)) return rv; - // XXX Extra copy and conversion. - // Jag will fix when he lands UTF8String - _retval.Assign(NS_ConvertUCS2toUTF8( - NS_ConvertASCIItoUCS2(tempCString))); + // XXX Extra copy, can be removed if we're sure tempCString can + // only contain ASCII. + CopyUTF16toUTF8(NS_ConvertASCIItoUTF16(tempCString), _retval); return NS_OK; } + } } /* static */ nsresult diff --git a/xpcom/io/nsLocalFileOSX.cpp b/xpcom/io/nsLocalFileOSX.cpp index d181801000e..7834c7024cc 100644 --- a/xpcom/io/nsLocalFileOSX.cpp +++ b/xpcom/io/nsLocalFileOSX.cpp @@ -515,7 +515,7 @@ NS_IMETHODIMP nsLocalFile::GetLeafName(nsAString& aLeafName) nsresult rv = GetNativeLeafName(nativeString); if (NS_FAILED(rv)) return rv; - aLeafName.Assign(NS_ConvertUTF8toUCS2(nativeString)); + CopyUTF8toUTF16(nativeString, aLeafName); return NS_OK; } @@ -814,7 +814,7 @@ NS_IMETHODIMP nsLocalFile::GetPath(nsAString& aPath) nsresult rv = GetNativePath(nativeString); if (NS_FAILED(rv)) return rv; - aPath.Assign(NS_ConvertUTF8toUCS2(nativeString)); + CopyUTF8toUTF16(nativeString, aPath); return NS_OK; } diff --git a/xpcom/io/nsNativeCharsetUtils.cpp b/xpcom/io/nsNativeCharsetUtils.cpp index 85be26134e2..7bf48cc23f0 100644 --- a/xpcom/io/nsNativeCharsetUtils.cpp +++ b/xpcom/io/nsNativeCharsetUtils.cpp @@ -844,14 +844,14 @@ NS_ShutdownNativeCharsetUtils() NS_COM nsresult NS_CopyNativeToUnicode(const nsACString &input, nsAString &output) { - output = NS_ConvertUTF8toUCS2(input); + CopyUTF8toUTF16(input, output); return NS_OK; } NS_COM nsresult NS_CopyUnicodeToNative(const nsAString &input, nsACString &output) { - output =NS_ConvertUCS2toUTF8(input); + CopyUTF16toUTF8(input, output); return NS_OK; }