Changeset 79842 in webkit
- Timestamp:
- Feb 27, 2011 10:53:41 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r79834 r79842 1 2011-02-27 Patrick Gansterer <paroga@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Remove registerBaseEncodingNames and registerBaseCodecs from TextCodecWinCE 6 https://bugs.webkit.org/show_bug.cgi?id=55317 7 8 This functions are obsolete, since r78499 added TextCodecUTF8. 9 Also remove the "fast path" for UTF-8 data, because we now have a separate TextCodec. 10 11 * platform/text/TextEncodingRegistry.cpp: 12 (WebCore::buildBaseTextCodecMaps): 13 * platform/text/wince/TextCodecWinCE.cpp: 14 * platform/text/wince/TextCodecWinCE.h: 15 1 16 2011-02-27 Benjamin Poulain <benjamin.poulain@nokia.com> 2 17 -
trunk/Source/WebCore/platform/text/TextEncodingRegistry.cpp
r79815 r79842 240 240 TextCodecGtk::registerBaseCodecs(addToTextCodecMap); 241 241 #endif 242 243 #if OS(WINCE) && !PLATFORM(QT)244 // FIXME: This is not needed. The code above covers all the base codecs.245 TextCodecWinCE::registerBaseEncodingNames(addToTextEncodingNameMap);246 TextCodecWinCE::registerBaseCodecs(addToTextCodecMap);247 #endif248 242 } 249 243 -
trunk/Source/WebCore/platform/text/wince/TextCodecWinCE.cpp
r77831 r79842 1 1 /* 2 2 * Copyright (C) 2007-2009 Torch Mobile, Inc. All rights reserved. 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>3 * Copyright (C) 2010-2011 Patrick Gansterer <paroga@paroga.com> 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without … … 36 36 #include <wtf/text/StringConcatenate.h> 37 37 #include <wtf/text/StringHash.h> 38 #include <wtf/unicode/UTF8.h>39 38 40 39 namespace WebCore { … … 123 122 static UINT getCodePage(const char* name) 124 123 { 125 if (!strcmp(name, "UTF-8"))126 return CP_UTF8;127 128 124 // Explicitly use a "const" reference to fix the silly VS build error 129 125 // saying "==" is not found for const_iterator and iterator … … 145 141 TextCodecWinCE::~TextCodecWinCE() 146 142 { 147 }148 149 void TextCodecWinCE::registerBaseEncodingNames(EncodingNameRegistrar registrar)150 {151 registrar("UTF-8", "UTF-8");152 }153 154 void TextCodecWinCE::registerBaseCodecs(TextCodecRegistrar registrar)155 {156 registrar("UTF-8", newTextCodecWinCE, 0);157 143 } 158 144 … … 182 168 static DWORD getCodePageFlags(UINT codePage) 183 169 { 184 if (codePage == CP_UTF8)185 return MB_ERR_INVALID_CHARS;186 187 170 if (codePage == 42) // Symbol 188 171 return 0; … … 214 197 } 215 198 216 static void decode (Vector<UChar, 8192>& result, UINT codePage, const char* bytes, size_t length, size_t* left, bool canBeFirstTime, bool& sawInvalidChar)199 static void decodeInternal(Vector<UChar, 8192>& result, UINT codePage, const char* bytes, size_t length, size_t* left) 217 200 { 218 201 *left = length; … … 222 205 DWORD flags = getCodePageFlags(codePage); 223 206 224 if (codePage == CP_UTF8) { 225 if (canBeFirstTime) { 226 // Handle BOM. 227 if (length > 3) { 228 if (bytes[0] == (char)0xEF && bytes[1] == (char)0xBB && bytes[2] == (char)0xBF) { 229 // BOM found! 230 length -= 3; 231 bytes += 3; 232 *left = length; 233 } 234 } else if (bytes[0] == 0xEF && (length < 2 || bytes[1] == (char)0xBB) && (length < 3 || bytes[2] == (char)0xBF)) { 235 if (length == 3) 236 *left = 0; 237 return; 207 int testLength = length; 208 int untestedLength = length; 209 for (;;) { 210 int resultLength = MultiByteToWideChar(codePage, flags, bytes, testLength, 0, 0); 211 212 if (resultLength > 0) { 213 int oldSize = result.size(); 214 result.resize(oldSize + resultLength); 215 216 MultiByteToWideChar(codePage, flags, bytes, testLength, result.data() + oldSize, resultLength); 217 218 if (testLength == untestedLength) { 219 *left = length - testLength; 220 break; 221 } 222 untestedLength -= testLength; 223 length -= testLength; 224 bytes += testLength; 225 } else { 226 untestedLength = testLength - 1; 227 if (!untestedLength) { 228 *left = length; 229 break; 238 230 } 239 231 } 240 241 // Process ASCII characters at beginning. 242 const char* firstNonAsciiChar = findFirstNonAsciiCharacter(bytes, length); 243 int numAsciiCharacters = firstNonAsciiChar - bytes; 244 if (numAsciiCharacters) { 245 result.append(bytes, numAsciiCharacters); 246 length -= numAsciiCharacters; 247 if (!length) { 248 *left = 0; 249 return; 250 } 251 bytes = firstNonAsciiChar; 252 } 253 254 int oldSize = result.size(); 255 result.resize(oldSize + length); 256 UChar* resultStart = result.data() + oldSize; 257 const char* sourceStart = bytes; 258 const char* const sourceEnd = bytes + length; 259 for (;;) { 260 using namespace WTF::Unicode; 261 ConversionResult convRes = convertUTF8ToUTF16(&sourceStart 262 , sourceEnd 263 , &resultStart 264 , result.data() + result.size() 265 , true); 266 267 // FIXME: is it possible? 268 if (convRes == targetExhausted && sourceStart < sourceEnd) { 269 oldSize = result.size(); 270 result.resize(oldSize + 256); 271 resultStart = result.data() + oldSize; 272 continue; 273 } 274 275 if (convRes != conversionOK) 276 sawInvalidChar = true; 277 278 break; 279 } 280 281 *left = sourceEnd - sourceStart; 282 result.resize(resultStart - result.data()); 283 } else { 284 int testLength = length; 285 int untestedLength = length; 286 for (;;) { 287 int resultLength = MultiByteToWideChar(codePage, flags, bytes, testLength, 0, 0); 288 289 if (resultLength > 0) { 290 int oldSize = result.size(); 291 result.resize(oldSize + resultLength); 292 293 MultiByteToWideChar(codePage, flags, bytes, testLength, result.data() + oldSize, resultLength); 294 295 if (testLength == untestedLength) { 296 *left = length - testLength; 297 break; 298 } 299 untestedLength -= testLength; 300 length -= testLength; 301 bytes += testLength; 302 } else { 303 untestedLength = testLength - 1; 304 if (!untestedLength) { 305 *left = length; 306 break; 307 } 308 } 309 testLength = (untestedLength + 1) / 2; 310 } 232 testLength = (untestedLength + 1) / 2; 311 233 } 312 234 } … … 323 245 Vector<UChar, 8192> result; 324 246 for (;;) { 325 bool sawInvalidChar = false; 326 WebCore::decode(result, m_codePage, bytes, length, &left, m_decodeBuffer.isEmpty(), sawInvalidChar); 247 decodeInternal(result, m_codePage, bytes, length, &left); 327 248 if (!left) 328 249 break; 329 250 330 if (! sawInvalidChar && !flush && left < 16)251 if (!flush && left < 16) 331 252 break; 332 253 … … 360 281 return CString(); 361 282 362 DWORD flags = m_codePage == CP_UTF8 ? 0 : WC_COMPOSITECHECK; 363 364 int resultLength = WideCharToMultiByte(m_codePage, flags, characters, length, 0, 0, 0, 0); 283 int resultLength = WideCharToMultiByte(m_codePage, WC_COMPOSITECHECK, characters, length, 0, 0, 0, 0); 365 284 366 285 // FIXME: We need to implement UnencodableHandling: QuestionMarksForUnencodables, EntitiesForUnencodables, and URLEncodedEntitiesForUnencodables. … … 372 291 CString result = CString::newUninitialized(resultLength, characterBuffer); 373 292 374 WideCharToMultiByte(m_codePage, flags, characters, length, characterBuffer, resultLength, 0, 0);293 WideCharToMultiByte(m_codePage, WC_COMPOSITECHECK, characters, length, characterBuffer, resultLength, 0, 0); 375 294 376 295 return result; -
trunk/Source/WebCore/platform/text/wince/TextCodecWinCE.h
r77831 r79842 40 40 class TextCodecWinCE : public TextCodec { 41 41 public: 42 static void registerBaseEncodingNames(EncodingNameRegistrar);43 static void registerBaseCodecs(TextCodecRegistrar);44 45 42 static void registerExtendedEncodingNames(EncodingNameRegistrar); 46 43 static void registerExtendedCodecs(TextCodecRegistrar);
Note: See TracChangeset
for help on using the changeset viewer.