From: ap Date: Tue, 9 May 2006 08:03:30 +0000 (+0000) Subject: Reviewed by Darin. X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=d0dfab12e46900fa547b214279f57657de2201ee Reviewed by Darin. - http://bugzilla.opendarwin.org/show_bug.cgi?id=8769 TextEncoding::fromUnicode() - support non-BMP characters and convert to NFC Fix the ICU code path, too (currently unused on the Mac). * platform/TextEncoding.cpp: (WebCore::TextEncoding::fromUnicode): Normalize the string. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14253 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 8249988089de..ff71e4b34cc0 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,15 @@ +2006-05-09 Alexey Proskuryakov + + Reviewed by Darin. + + - http://bugzilla.opendarwin.org/show_bug.cgi?id=8769 + TextEncoding::fromUnicode() - support non-BMP characters and convert to NFC + + Fix the ICU code path, too (currently unused on the Mac). + + * platform/TextEncoding.cpp: + (WebCore::TextEncoding::fromUnicode): Normalize the string. + 2006-05-08 Maciej Stachowiak Reviewed by Tim Hatcher. diff --git a/WebCore/platform/TextEncoding.cpp b/WebCore/platform/TextEncoding.cpp index 022c3349d97e..33cf82ed5b08 100644 --- a/WebCore/platform/TextEncoding.cpp +++ b/WebCore/platform/TextEncoding.cpp @@ -30,6 +30,7 @@ #include #include #include "StreamingTextDecoder.h" +#include namespace WebCore { @@ -143,7 +144,22 @@ DeprecatedCString TextEncoding::fromUnicode(const DeprecatedString &qcs, bool al const UChar* source = reinterpret_cast(copy.unicode()); const UChar* sourceLimit = source + copy.length(); - DeprecatedCString result(1); // for trailng zero + DeprecatedString normalizedString; + if (UNORM_YES != unorm_quickCheck(source, copy.length(), UNORM_NFC, &err)) { + normalizedString.truncate(copy.length()); // normalization to NFC rarely increases the length, so this first attempt will usually succeed + + int32_t normalizedLength = unorm_normalize(source, copy.length(), UNORM_NFC, 0, reinterpret_cast(const_cast(normalizedString.unicode())), copy.length(), &err); + if (err == U_BUFFER_OVERFLOW_ERROR) { + err = U_ZERO_ERROR; + normalizedString.truncate(normalizedLength); + normalizedLength = unorm_normalize(source, copy.length(), UNORM_NFC, 0, reinterpret_cast(const_cast(normalizedString.unicode())), normalizedLength, &err); + } + + source = reinterpret_cast(normalizedString.unicode()); + sourceLimit = source + normalizedLength; + } + + DeprecatedCString result(1); // for trailing zero if (allowEntities) ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err); @@ -152,6 +168,10 @@ DeprecatedCString TextEncoding::fromUnicode(const DeprecatedString &qcs, bool al ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, 0, 0, &err); } + ASSERT(U_SUCCESS(err)); + if (U_FAILURE(err)) + return DeprecatedCString(); + do { char* target = buffer; char* targetLimit = target + ConversionBufferSize;