diff options
Diffstat (limited to 'WebCore/platform/text/TextCodecLatin1.cpp')
-rw-r--r-- | WebCore/platform/text/TextCodecLatin1.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/WebCore/platform/text/TextCodecLatin1.cpp b/WebCore/platform/text/TextCodecLatin1.cpp index a687235..50f9f97 100644 --- a/WebCore/platform/text/TextCodecLatin1.cpp +++ b/WebCore/platform/text/TextCodecLatin1.cpp @@ -29,6 +29,7 @@ #include "CString.h" #include "PlatformString.h" #include "StringBuffer.h" +#include <stdio.h> using std::auto_ptr; @@ -117,7 +118,7 @@ void TextCodecLatin1::registerCodecs(TextCodecRegistrar registrar) registrar("US-ASCII", newStreamingTextDecoderWindowsLatin1, 0); } -String TextCodecLatin1::decode(const char* bytes, size_t length, bool) +String TextCodecLatin1::decode(const char* bytes, size_t length, bool, bool, bool&) { StringBuffer characters(length); @@ -141,7 +142,7 @@ String TextCodecLatin1::decode(const char* bytes, size_t length, bool) return String::adopt(characters); } -static CString encodeComplexWindowsLatin1(const UChar* characters, size_t length, bool allowEntities) +static CString encodeComplexWindowsLatin1(const UChar* characters, size_t length, UnencodableHandling handling) { Vector<char> result(length); char* bytes = result.data(); @@ -158,17 +159,13 @@ static CString encodeComplexWindowsLatin1(const UChar* characters, size_t length if (table[b] == c) goto gotByte; // No way to encode this character with Windows Latin-1. - if (allowEntities) { - char entityBuffer[16]; - sprintf(entityBuffer, "&#%u;", c); - size_t entityLength = strlen(entityBuffer); - result.grow(resultLength + entityLength + length - i); - bytes = result.data(); - memcpy(bytes + resultLength, entityBuffer, entityLength); - resultLength += entityLength; - continue; - } - b = '?'; + UnencodableReplacementArray replacement; + int replacementLength = TextCodec::getUnencodableReplacement(c, handling, replacement); + result.grow(resultLength + replacementLength + length - i); + bytes = result.data(); + memcpy(bytes + resultLength, replacement, replacementLength); + resultLength += replacementLength; + continue; } gotByte: bytes[resultLength++] = b; @@ -177,7 +174,7 @@ static CString encodeComplexWindowsLatin1(const UChar* characters, size_t length return CString(bytes, resultLength); } -CString TextCodecLatin1::encode(const UChar* characters, size_t length, bool allowEntities) +CString TextCodecLatin1::encode(const UChar* characters, size_t length, UnencodableHandling handling) { { char* bytes; @@ -196,7 +193,7 @@ CString TextCodecLatin1::encode(const UChar* characters, size_t length, bool all } // If it wasn't all ASCII, call the function that handles more-complex cases. - return encodeComplexWindowsLatin1(characters, length, allowEntities); + return encodeComplexWindowsLatin1(characters, length, handling); } } // namespace WebCore |