diff --git a/intl/uconv/ucvlatin/Makefile.in b/intl/uconv/ucvlatin/Makefile.in index 3e7a3683622b..62761318a4b6 100644 --- a/intl/uconv/ucvlatin/Makefile.in +++ b/intl/uconv/ucvlatin/Makefile.in @@ -48,6 +48,7 @@ FORCE_STATIC_LIB = 1 LIBXUL_LIBRARY = 1 REQUIRES = xpcom \ + string \ uconv \ $(NULL) diff --git a/intl/uconv/ucvlatin/nsUTF32ToUnicode.cpp b/intl/uconv/ucvlatin/nsUTF32ToUnicode.cpp index 03304e5b1a3e..e659205fdf72 100644 --- a/intl/uconv/ucvlatin/nsUTF32ToUnicode.cpp +++ b/intl/uconv/ucvlatin/nsUTF32ToUnicode.cpp @@ -40,6 +40,7 @@ #include "nsUCSupport.h" #include "nsUTF32ToUnicode.h" +#include "nsCharTraits.h" #include //---------------------------------------------------------------------- @@ -96,9 +97,7 @@ static nsresult ConvertCommon(const char * aSrc, ucs4 = aIsLE ? LE_STRING_TO_UCS4(aBuffer) : BE_STRING_TO_UCS4(aBuffer); if (ucs4 < 0x10000L) // BMP { - // XXX Do we have to convert surrogate code points to the replacement - // character (0xfffd)? - *dest++= PRUnichar(ucs4); + *dest++= IS_SURROGATE(ucs4) ? UCS2_REPLACEMENT_CHAR : PRUnichar(ucs4); } else if (ucs4 < 0x110000L) // plane 1 through plane 16 { @@ -108,9 +107,8 @@ static nsresult ConvertCommon(const char * aSrc, *aDestLength = 0; return NS_OK_UDEC_MOREOUTPUT; } - // ((ucs4 - 0x10000) >> 10) + 0xd800; - *dest++= PRUnichar((ucs4 >> 10) + 0xd7c0); // high surrogate - *dest++= PRUnichar(ucs4 & 0x3ffL | 0xdc00); // low surrogate + *dest++= H_SURROGATE(ucs4); + *dest++= L_SURROGATE(ucs4); } // Codepoints in plane 17 and higher (> 0x10ffff) // are not representable in UTF-16 we use for the internal @@ -119,7 +117,7 @@ static nsresult ConvertCommon(const char * aSrc, // in plane 17 and higher. Therefore, we convert them // to Unicode replacement character (0xfffd). else - *dest++ = 0xfffd; + *dest++ = UCS2_REPLACEMENT_CHAR; src += *aState; *aState = 0; } @@ -141,20 +139,18 @@ static nsresult ConvertCommon(const char * aSrc, ucs4 = aIsLE ? LE_STRING_TO_UCS4(src) : BE_STRING_TO_UCS4(src); if (ucs4 < 0x10000L) // BMP { - // XXX Do we have to convert surrogate code points to the replacement - // character (0xfffd)? - *dest++= PRUnichar(ucs4); + *dest++= IS_SURROGATE(ucs4) ? UCS2_REPLACEMENT_CHAR : PRUnichar(ucs4); } else if (ucs4 < 0x110000L) // plane 1 through plane 16 { if (destEnd - dest < 2) break; // ((ucs4 - 0x10000) >> 10) + 0xd800; - *dest++= PRUnichar((ucs4 >> 10) + 0xd7c0); - *dest++= PRUnichar(ucs4 & 0x3ffL | 0xdc00); + *dest++= H_SURROGATE(ucs4); + *dest++= L_SURROGATE(ucs4); } else // plane 17 and higher - *dest++ = 0xfffd; + *dest++ = UCS2_REPLACEMENT_CHAR; } //output not finished, output buffer too short