Changeset 79842 in webkit


Ignore:
Timestamp:
Feb 27, 2011 10:53:41 PM (13 years ago)
Author:
Patrick Gansterer
Message:

2011-02-27 Patrick Gansterer <Patrick Gansterer>

Reviewed by Darin Adler.

Remove registerBaseEncodingNames and registerBaseCodecs from TextCodecWinCE
https://bugs.webkit.org/show_bug.cgi?id=55317

This functions are obsolete, since r78499 added TextCodecUTF8.
Also remove the "fast path" for UTF-8 data, because we now have a separate TextCodec.

  • platform/text/TextEncodingRegistry.cpp: (WebCore::buildBaseTextCodecMaps):
  • platform/text/wince/TextCodecWinCE.cpp:
  • platform/text/wince/TextCodecWinCE.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r79834 r79842  
     12011-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
    1162011-02-27  Benjamin Poulain  <benjamin.poulain@nokia.com>
    217
  • trunk/Source/WebCore/platform/text/TextEncodingRegistry.cpp

    r79815 r79842  
    240240    TextCodecGtk::registerBaseCodecs(addToTextCodecMap);
    241241#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 #endif
    248242}
    249243
  • trunk/Source/WebCore/platform/text/wince/TextCodecWinCE.cpp

    r77831 r79842  
    11/*
    22 * 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>
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    3636#include <wtf/text/StringConcatenate.h>
    3737#include <wtf/text/StringHash.h>
    38 #include <wtf/unicode/UTF8.h>
    3938
    4039namespace WebCore {
     
    123122static UINT getCodePage(const char* name)
    124123{
    125     if (!strcmp(name, "UTF-8"))
    126         return CP_UTF8;
    127 
    128124    // Explicitly use a "const" reference to fix the silly VS build error
    129125    // saying "==" is not found for const_iterator and iterator
     
    145141TextCodecWinCE::~TextCodecWinCE()
    146142{
    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);
    157143}
    158144
     
    182168static DWORD getCodePageFlags(UINT codePage)
    183169{
    184     if (codePage == CP_UTF8)
    185         return MB_ERR_INVALID_CHARS;
    186 
    187170    if (codePage == 42) // Symbol
    188171        return 0;
     
    214197}
    215198
    216 static void decode(Vector<UChar, 8192>& result, UINT codePage, const char* bytes, size_t length, size_t* left, bool canBeFirstTime, bool& sawInvalidChar)
     199static void decodeInternal(Vector<UChar, 8192>& result, UINT codePage, const char* bytes, size_t length, size_t* left)
    217200{
    218201    *left = length;
     
    222205    DWORD flags = getCodePageFlags(codePage);
    223206
    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;
    238230            }
    239231        }
    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;
    311233    }
    312234}
     
    323245    Vector<UChar, 8192> result;
    324246    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);
    327248        if (!left)
    328249            break;
    329250
    330         if (!sawInvalidChar && !flush && left < 16)
     251        if (!flush && left < 16)
    331252            break;
    332253
     
    360281        return CString();
    361282
    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);
    365284
    366285    // FIXME: We need to implement UnencodableHandling: QuestionMarksForUnencodables, EntitiesForUnencodables, and URLEncodedEntitiesForUnencodables.
     
    372291    CString result = CString::newUninitialized(resultLength, characterBuffer);
    373292
    374     WideCharToMultiByte(m_codePage, flags, characters, length, characterBuffer, resultLength, 0, 0);
     293    WideCharToMultiByte(m_codePage, WC_COMPOSITECHECK, characters, length, characterBuffer, resultLength, 0, 0);
    375294
    376295    return result;
  • trunk/Source/WebCore/platform/text/wince/TextCodecWinCE.h

    r77831 r79842  
    4040class TextCodecWinCE : public TextCodec {
    4141public:
    42     static void registerBaseEncodingNames(EncodingNameRegistrar);
    43     static void registerBaseCodecs(TextCodecRegistrar);
    44 
    4542    static void registerExtendedEncodingNames(EncodingNameRegistrar);
    4643    static void registerExtendedCodecs(TextCodecRegistrar);
Note: See TracChangeset for help on using the changeset viewer.