Chromium Code Reviews| Index: Source/wtf/text/TextEncoding.cpp |
| diff --git a/Source/wtf/text/TextEncoding.cpp b/Source/wtf/text/TextEncoding.cpp |
| index 90a31d487f99ff88e57b3ff08605d7a6e8429242..3164bc414caa6595a0d51cac4d6ddd965efeb31a 100644 |
| --- a/Source/wtf/text/TextEncoding.cpp |
| +++ b/Source/wtf/text/TextEncoding.cpp |
| @@ -72,6 +72,23 @@ CString TextEncoding::encode(const String& string, UnencodableHandling handling) |
| if (string.isEmpty()) |
| return ""; |
| + OwnPtr<TextCodec> textCodec = newTextCodec(*this); |
| + CString encodedString; |
| + if (string.is8Bit()) |
| + encodedString = textCodec->encode(string.characters8(), string.length(), handling); |
| + else |
| + encodedString = textCodec->encode(string.characters16(), string.length(), handling); |
| + return encodedString; |
| +} |
| + |
| +CString TextEncoding::normalizeAndEncode(const String& string, UnencodableHandling handling) const |
| +{ |
| + if (!m_name) |
| + return CString(); |
| + |
| + if (string.isEmpty()) |
| + return ""; |
| + |
| // Text exclusively containing Latin-1 characters (U+0000..U+00FF) is left |
| // unaffected by NFC. This is effectively the same as saying that all |
| // Latin-1 text is already normalized to NFC. |
| @@ -79,18 +96,13 @@ CString TextEncoding::encode(const String& string, UnencodableHandling handling) |
| if (string.is8Bit()) |
| return newTextCodec(*this)->encode(string.characters8(), string.length(), handling); |
| - // FIXME: What's the right place to do normalization? |
| - // It's a little strange to do it inside the encode function. |
| - // Perhaps normalization should be an explicit step done before calling encode. |
| - |
| const UChar* source = string.characters16(); |
| size_t length = string.length(); |
| - Vector<UChar> normalizedCharacters; |
| - |
| UErrorCode err = U_ZERO_ERROR; |
| if (unorm_quickCheck(source, length, UNORM_NFC, &err) != UNORM_YES) { |
| // First try using the length of the original string, since normalization to NFC rarely increases length. |
| + Vector<UChar> normalizedCharacters; |
|
abarth-chromium
2013/07/24 18:20:09
Moving this declaration inside the if statement ca
|
| normalizedCharacters.grow(length); |
| int32_t normalizedLength = unorm_normalize(source, length, UNORM_NFC, 0, normalizedCharacters.data(), length, &err); |
| if (err == U_BUFFER_OVERFLOW_ERROR) { |