diff --git a/mozilla/string/public/nsReadableUtils.h b/mozilla/string/public/nsReadableUtils.h index cb4194fc9d6..b8b5fe0df3a 100755 --- a/mozilla/string/public/nsReadableUtils.h +++ b/mozilla/string/public/nsReadableUtils.h @@ -47,6 +47,11 @@ NS_COM size_t Distance( const nsReadingIterator&, const nsReadingIterator< NS_COM void CopyUCS2toASCII( const nsAString& aSource, nsACString& aDest ); NS_COM void CopyASCIItoUCS2( const nsACString& aSource, nsAString& aDest ); +NS_COM void CopyUCS2toUTF8( const nsAString& aSource, nsACString& aDest ); +NS_COM void CopyUTF8toUCS2( const nsACString& aSource, nsAString& aDest ); + +NS_COM void AppendUCS2toUTF8( const nsAString& aSource, nsACString& aDest ); +NS_COM void AppendUTF8toUCS2( const nsACString& aSource, nsAString& aDest ); /** * Returns a new |char| buffer containing a zero-terminated copy of |aSource|. diff --git a/mozilla/string/src/nsReadableUtils.cpp b/mozilla/string/src/nsReadableUtils.cpp index 6f8aa523b86..6c6d8ca699c 100755 --- a/mozilla/string/src/nsReadableUtils.cpp +++ b/mozilla/string/src/nsReadableUtils.cpp @@ -176,6 +176,42 @@ CopyASCIItoUCS2( const nsACString& aSource, nsAString& aDest ) copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd), converter); } +NS_COM +void +CopyUCS2toUTF8( const nsAString& aSource, nsACString& aDest ) + { + aDest.Truncate(); + AppendUCS2toUTF8(aSource, aDest); + } + +NS_COM +void +CopyUTF8toUCS2( const nsACString& aSource, nsAString& aDest ) + { + aDest.Truncate(); + AppendUTF8toUCS2(aSource, aDest); + } + +NS_COM +void +AppendUCS2toUTF8( const nsAString& aSource, nsACString& aDest ) + { + // This isn't the fastest possible implementation of this method, + // but it works, and that's better than nothing! + + aDest.Append(NS_ConvertUCS2toUTF8(aSource)); + } + +NS_COM +void +AppendUTF8toUCS2( const nsACString& aSource, nsAString& aDest ) + { + // This isn't the fastest possible implementation of this method, + // but it works, and that's better than nothing! + + aDest.Append(NS_ConvertUTF8toUCS2(aSource)); + } + /** * A helper function that allocates a buffer of the desired character type big enough to hold a copy of the supplied string (plus a zero terminator). diff --git a/mozilla/xpcom/string/public/nsReadableUtils.h b/mozilla/xpcom/string/public/nsReadableUtils.h index cb4194fc9d6..b8b5fe0df3a 100755 --- a/mozilla/xpcom/string/public/nsReadableUtils.h +++ b/mozilla/xpcom/string/public/nsReadableUtils.h @@ -47,6 +47,11 @@ NS_COM size_t Distance( const nsReadingIterator&, const nsReadingIterator< NS_COM void CopyUCS2toASCII( const nsAString& aSource, nsACString& aDest ); NS_COM void CopyASCIItoUCS2( const nsACString& aSource, nsAString& aDest ); +NS_COM void CopyUCS2toUTF8( const nsAString& aSource, nsACString& aDest ); +NS_COM void CopyUTF8toUCS2( const nsACString& aSource, nsAString& aDest ); + +NS_COM void AppendUCS2toUTF8( const nsAString& aSource, nsACString& aDest ); +NS_COM void AppendUTF8toUCS2( const nsACString& aSource, nsAString& aDest ); /** * Returns a new |char| buffer containing a zero-terminated copy of |aSource|. diff --git a/mozilla/xpcom/string/src/nsReadableUtils.cpp b/mozilla/xpcom/string/src/nsReadableUtils.cpp index 6f8aa523b86..6c6d8ca699c 100755 --- a/mozilla/xpcom/string/src/nsReadableUtils.cpp +++ b/mozilla/xpcom/string/src/nsReadableUtils.cpp @@ -176,6 +176,42 @@ CopyASCIItoUCS2( const nsACString& aSource, nsAString& aDest ) copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd), converter); } +NS_COM +void +CopyUCS2toUTF8( const nsAString& aSource, nsACString& aDest ) + { + aDest.Truncate(); + AppendUCS2toUTF8(aSource, aDest); + } + +NS_COM +void +CopyUTF8toUCS2( const nsACString& aSource, nsAString& aDest ) + { + aDest.Truncate(); + AppendUTF8toUCS2(aSource, aDest); + } + +NS_COM +void +AppendUCS2toUTF8( const nsAString& aSource, nsACString& aDest ) + { + // This isn't the fastest possible implementation of this method, + // but it works, and that's better than nothing! + + aDest.Append(NS_ConvertUCS2toUTF8(aSource)); + } + +NS_COM +void +AppendUTF8toUCS2( const nsACString& aSource, nsAString& aDest ) + { + // This isn't the fastest possible implementation of this method, + // but it works, and that's better than nothing! + + aDest.Append(NS_ConvertUTF8toUCS2(aSource)); + } + /** * A helper function that allocates a buffer of the desired character type big enough to hold a copy of the supplied string (plus a zero terminator).