Modified: trunk/Source/WebCore/ChangeLog (149923 => 149924)
--- trunk/Source/WebCore/ChangeLog 2013-05-11 05:03:10 UTC (rev 149923)
+++ trunk/Source/WebCore/ChangeLog 2013-05-11 05:45:45 UTC (rev 149924)
@@ -1,3 +1,19 @@
+2013-05-10 Alexey Proskuryakov <[email protected]>
+
+ Make TextCodecICU not depend on TextEncoding
+ https://bugs.webkit.org/show_bug.cgi?id=115848
+
+ Reviewed by Darin Adler.
+
+ * platform/text/TextCodecICU.cpp:
+ (WebCore::TextCodecICU::create):
+ (WebCore::TextCodecICU::TextCodecICU):
+ (WebCore::TextCodecICU::createICUConverter):
+ (WebCore::TextCodecICU::decode):
+ (WebCore::TextCodecICU::encode):
+ * platform/text/TextCodecICU.h:
+ Use a plain encoding string in platform encoder wrapper, not a higher level concept.
+
2013-05-10 Laszlo Gombos <[email protected]>
Remove Mac OS X Leopard (10.5) support
Modified: trunk/Source/WebCore/platform/text/TextCodecICU.cpp (149923 => 149924)
--- trunk/Source/WebCore/platform/text/TextCodecICU.cpp 2013-05-11 05:03:10 UTC (rev 149923)
+++ trunk/Source/WebCore/platform/text/TextCodecICU.cpp 2013-05-11 05:45:45 UTC (rev 149924)
@@ -28,6 +28,8 @@
#if USE(ICU_UNICODE)
#include "TextCodecICU.h"
+#include "TextEncoding.h"
+#include "TextEncodingRegistry.h"
#include "ThreadGlobalData.h"
#include <unicode/ucnv.h>
#include <unicode/ucnv_cb.h>
@@ -57,7 +59,8 @@
PassOwnPtr<TextCodec> TextCodecICU::create(const TextEncoding& encoding, const void*)
{
- return adoptPtr(new TextCodecICU(encoding));
+ // TextEncoding name is always one from atomicCanonicalTextEncodingName, guaranteed to never be deleted.
+ return adoptPtr(new TextCodecICU(encoding.name()));
}
void TextCodecICU::registerEncodingNames(EncodingNameRegistrar registrar)
@@ -197,8 +200,8 @@
}
}
-TextCodecICU::TextCodecICU(const TextEncoding& encoding)
- : m_encoding(encoding)
+TextCodecICU::TextCodecICU(const char* encoding)
+ : m_encodingName(encoding)
, m_converterICU(0)
, m_needsGBKFallbacks(false)
{
@@ -224,8 +227,7 @@
{
ASSERT(!m_converterICU);
- const char* name = m_encoding.name();
- m_needsGBKFallbacks = name[0] == 'G' && name[1] == 'B' && name[2] == 'K' && !name[3];
+ m_needsGBKFallbacks = m_encodingName[0] == 'G' && m_encodingName[1] == 'B' && m_encodingName[2] == 'K' && !m_encodingName[3];
UErrorCode err;
@@ -233,7 +235,7 @@
if (cachedConverter) {
err = U_ZERO_ERROR;
const char* cachedName = ucnv_getName(cachedConverter, &err);
- if (U_SUCCESS(err) && m_encoding == cachedName) {
+ if (U_SUCCESS(err) && m_encodingName == cachedName) {
m_converterICU = cachedConverter;
cachedConverter = 0;
return;
@@ -241,10 +243,10 @@
}
err = U_ZERO_ERROR;
- m_converterICU = ucnv_open(m_encoding.name(), &err);
+ m_converterICU = ucnv_open(m_encodingName, &err);
#if !LOG_DISABLED
if (err == U_AMBIGUOUS_ALIAS_WARNING)
- LOG_ERROR("ICU ambiguous alias warning for encoding: %s", m_encoding.name());
+ LOG_ERROR("ICU ambiguous alias warning for encoding: %s", m_encodingName);
#endif
if (m_converterICU)
ucnv_setFallback(m_converterICU, TRUE);
@@ -334,7 +336,7 @@
// <http://bugs.webkit.org/show_bug.cgi?id=17014>
// Simplified Chinese pages use the code A3A0 to mean "full-width space", but ICU decodes it as U+E5E5.
- if (strcmp(m_encoding.name(), "GBK") == 0 || strcasecmp(m_encoding.name(), "gb18030") == 0)
+ if (strcmp(m_encodingName, "GBK") == 0 || strcasecmp(m_encodingName, "gb18030") == 0)
resultString.replace(0xE5E5, ideographicSpace);
return resultString;
@@ -429,12 +431,19 @@
// FIXME: We should see if there is "force ASCII range" mode in ICU;
// until then, we change the backslash into a yen sign.
// Encoding will change the yen sign back into a backslash.
- String copy(characters, length);
- copy = m_encoding.displayString(copy.impl());
+ String copy;
+ const UChar* source;
+ const UChar* sourceLimit;
+ if (shouldShowBackslashAsCurrencySymbolIn(m_encodingName)) {
+ copy.append(characters, length);
+ copy.replace('\\', 0xA5);
+ source = copy.characters();
+ sourceLimit = source + copy.length();
+ } else {
+ source = characters;
+ sourceLimit = source + length;
+ }
- const UChar* source = copy.characters();
- const UChar* sourceLimit = source + copy.length();
-
UErrorCode err = U_ZERO_ERROR;
switch (handling) {
Modified: trunk/Source/WebCore/platform/text/TextCodecICU.h (149923 => 149924)
--- trunk/Source/WebCore/platform/text/TextCodecICU.h 2013-05-11 05:03:10 UTC (rev 149923)
+++ trunk/Source/WebCore/platform/text/TextCodecICU.h 2013-05-11 05:45:45 UTC (rev 149924)
@@ -28,7 +28,6 @@
#define TextCodecICU_h
#include "TextCodec.h"
-#include "TextEncoding.h"
#include <unicode/utypes.h>
typedef struct UConverter UConverter;
@@ -43,7 +42,7 @@
virtual ~TextCodecICU();
private:
- TextCodecICU(const TextEncoding&);
+ explicit TextCodecICU(const char* encoding);
static PassOwnPtr<TextCodec> create(const TextEncoding&, const void*);
virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
@@ -57,7 +56,7 @@
int decodeToBuffer(UChar* buffer, UChar* bufferLimit, const char*& source,
const char* sourceLimit, int32_t* offsets, bool flush, UErrorCode& err);
- TextEncoding m_encoding;
+ const char* const m_encodingName;
mutable UConverter* m_converterICU;
mutable bool m_needsGBKFallbacks;
};