diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
commit | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch) | |
tree | 4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/platform/text/mac/TextCodecMac.cpp | |
parent | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff) | |
download | external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/platform/text/mac/TextCodecMac.cpp')
-rw-r--r-- | WebCore/platform/text/mac/TextCodecMac.cpp | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/WebCore/platform/text/mac/TextCodecMac.cpp b/WebCore/platform/text/mac/TextCodecMac.cpp index 7270a26..ac1f0fb 100644 --- a/WebCore/platform/text/mac/TextCodecMac.cpp +++ b/WebCore/platform/text/mac/TextCodecMac.cpp @@ -78,7 +78,6 @@ void TextCodecMac::registerCodecs(TextCodecRegistrar registrar) TextCodecMac::TextCodecMac(TECTextEncodingID encoding) : m_encoding(encoding) - , m_error(false) , m_numBufferedBytes(0) , m_converterTEC(0) { @@ -179,16 +178,15 @@ OSStatus TextCodecMac::decode(const unsigned char* inputBuffer, int inputBufferL } // Work around bug 3351093, where sometimes we get kTECBufferBelowMinimumSizeErr instead of kTECOutputBufferFullStatus. - if (status == kTECBufferBelowMinimumSizeErr && bytesWritten != 0) { + if (status == kTECBufferBelowMinimumSizeErr && bytesWritten != 0) status = kTECOutputBufferFullStatus; - } inputLength = bytesRead; outputLength = bytesWritten; return status; } -String TextCodecMac::decode(const char* bytes, size_t length, bool flush) +String TextCodecMac::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError) { // Get a converter for the passed-in encoding. if (!m_converterTEC && createTECConverter() != noErr) @@ -201,7 +199,7 @@ String TextCodecMac::decode(const char* bytes, size_t length, bool flush) bool bufferWasFull = false; UniChar buffer[ConversionBufferSize]; - while (sourceLength || bufferWasFull) { + while ((sourceLength || bufferWasFull) && !sawError) { int bytesRead = 0; int bytesWritten = 0; OSStatus status = decode(sourcePointer, sourceLength, bytesRead, buffer, sizeof(buffer), bytesWritten); @@ -217,6 +215,10 @@ String TextCodecMac::decode(const char* bytes, size_t length, bool flush) case kTextUndefinedElementErr: // FIXME: Put FFFD character into the output string in this case? TECClearConverterContextInfo(m_converterTEC); + if (stopOnError) { + sawError = true; + break; + } if (sourceLength) { sourcePointer += 1; sourceLength -= 1; @@ -236,13 +238,12 @@ String TextCodecMac::decode(const char* bytes, size_t length, bool flush) break; } default: - LOG_ERROR("text decoding failed with error %ld", static_cast<long>(status)); - m_error = true; + sawError = true; return String(); } ASSERT(!(bytesWritten % sizeof(UChar))); - appendOmittingBOM(result, buffer, bytesWritten / sizeof(UChar)); + result.append(buffer, bytesWritten / sizeof(UChar)); bufferWasFull = status == kTECOutputBufferFullStatus; } @@ -251,7 +252,7 @@ String TextCodecMac::decode(const char* bytes, size_t length, bool flush) unsigned long bytesWritten = 0; TECFlushText(m_converterTEC, reinterpret_cast<unsigned char*>(buffer), sizeof(buffer), &bytesWritten); ASSERT(!(bytesWritten % sizeof(UChar))); - appendOmittingBOM(result, buffer, bytesWritten / sizeof(UChar)); + result.append(buffer, bytesWritten / sizeof(UChar)); } String resultString = String::adopt(result); @@ -266,7 +267,7 @@ String TextCodecMac::decode(const char* bytes, size_t length, bool flush) return resultString; } -CString TextCodecMac::encode(const UChar* characters, size_t length, bool allowEntities) +CString TextCodecMac::encode(const UChar* characters, size_t length, UnencodableHandling handling) { // FIXME: We should really use TEC here instead of CFString for consistency with the other direction. @@ -280,7 +281,7 @@ CString TextCodecMac::encode(const UChar* characters, size_t length, bool allowE CFIndex charactersLeft = CFStringGetLength(cfs); Vector<char> result; size_t size = 0; - UInt8 lossByte = allowEntities ? 0 : '?'; + UInt8 lossByte = handling == QuestionMarksForUnencodables ? '?' : 0; while (charactersLeft > 0) { CFRange range = CFRangeMake(startPos, charactersLeft); CFIndex bufferLength; @@ -303,11 +304,10 @@ CString TextCodecMac::encode(const UChar* characters, size_t length, bool allowE ++charactersConverted; } } - char entityBuffer[16]; - sprintf(entityBuffer, "&#%u;", badChar); - size_t entityLength = strlen(entityBuffer); + UnencodableReplacementArray entity; + int entityLength = getUnencodableReplacement(badChar, handling, entity); result.grow(size + entityLength); - memcpy(result.data() + size, entityBuffer, entityLength); + memcpy(result.data() + size, entity, entityLength); size += entityLength; } |