Changeset 140731 in webkit


Ignore:
Timestamp:
Jan 24, 2013 3:01:06 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Abstract the logic for appending a UChar32 onto StringBuilder
https://bugs.webkit.org/show_bug.cgi?id=107505

Patch by Martin Robinson <mrobinson@igalia.com> on 2013-01-24
Reviewed by Darin Adler.

Source/WebCore:

  • css/CSSOMUtils.cpp:

(WebCore::serializeCharacter): Use the new StringBuilder append.
(WebCore::serializeIdentifier): Ditto.
(WebCore::serializeString): Ditto.

  • html/parser/HTMLEntityParser.cpp:

(WebCore::HTMLEntityParser::consumeNamedEntity): Ditto.

  • svg/SVGFontData.cpp:

(WebCore::SVGFontData::createStringWithMirroredCharacters): Ditto.

  • xml/parser/CharacterReferenceParserInlines.h:

(WebCore::consumeCharacterReference): Ditto.

  • xml/parser/XMLCharacterReferenceParser.cpp: Remove an older helper

superseded by StringBuilder::append.

Source/WTF:

  • wtf/text/StringBuilder.h:

(WTF::StringBuilder::append): Added a method for appending a UChar32 to a StringBuilder.

Tools:

  • TestWebKitAPI/Tests/WTF/StringBuilder.cpp:

(TestWebKitAPI::TEST): Added a simple test for appending UChar32.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r140695 r140731  
     12013-01-24  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Abstract the logic for appending a UChar32 onto StringBuilder
     4        https://bugs.webkit.org/show_bug.cgi?id=107505
     5
     6        Reviewed by Darin Adler.
     7
     8        * wtf/text/StringBuilder.h:
     9        (WTF::StringBuilder::append): Added a method for appending a UChar32 to a StringBuilder.
     10
    1112013-01-24  Brent Fulgham  <bfulgham@webkit.org>
    212
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r133726 r140731  
    142142    }
    143143
     144    void append(UChar32 c)
     145    {
     146        if (U_IS_BMP(c)) {
     147            append(static_cast<UChar>(c));
     148            return;
     149        }
     150        append(U16_LEAD(c));
     151        append(U16_TRAIL(c));
     152    }
     153
    144154    template<unsigned charactersCount>
    145155    ALWAYS_INLINE void appendLiteral(const char (&characters)[charactersCount]) { append(characters, charactersCount - 1); }
  • trunk/Source/WebCore/ChangeLog

    r140729 r140731  
     12013-01-24  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Abstract the logic for appending a UChar32 onto StringBuilder
     4        https://bugs.webkit.org/show_bug.cgi?id=107505
     5
     6        Reviewed by Darin Adler.
     7
     8        * css/CSSOMUtils.cpp:
     9        (WebCore::serializeCharacter): Use the new StringBuilder append.
     10        (WebCore::serializeIdentifier): Ditto.
     11        (WebCore::serializeString): Ditto.
     12        * html/parser/HTMLEntityParser.cpp:
     13        (WebCore::HTMLEntityParser::consumeNamedEntity): Ditto.
     14        * svg/SVGFontData.cpp:
     15        (WebCore::SVGFontData::createStringWithMirroredCharacters): Ditto.
     16        * xml/parser/CharacterReferenceParserInlines.h:
     17        (WebCore::consumeCharacterReference): Ditto.
     18        * xml/parser/XMLCharacterReferenceParser.cpp: Remove an older helper
     19        superseded by StringBuilder::append.
     20
    1212013-01-24  Kentaro Hara  <haraken@chromium.org>
    222
  • trunk/Source/WebCore/css/CSSOMUtils.cpp

    r95901 r140731  
    3737namespace WebCore {
    3838
    39 static void appendCharacter(UChar32 c, StringBuilder& appendTo)
    40 {
    41     if (U16_LENGTH(c) == 1)
    42         appendTo.append(static_cast<UChar>(c));
    43     else {
    44         appendTo.append(U16_LEAD(c));
    45         appendTo.append(U16_TRAIL(c));
    46     }
    47 }
    48 
    4939void serializeCharacter(UChar32 c, StringBuilder& appendTo)
    5040{
    5141    appendTo.append('\\');
    52     appendCharacter(c, appendTo);
     42    appendTo.append(c);
    5343}
    5444
     
    8272            serializeCharacter(c, appendTo);
    8373        else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
    84             appendCharacter(c, appendTo);
     74            appendTo.append(c);
    8575        else
    8676            serializeCharacter(c, appendTo);
     
    116106            serializeCharacter(c, appendTo);
    117107        else
    118             appendCharacter(c, appendTo);
     108            appendTo.append(c);
    119109    }
    120110
  • trunk/Source/WebCore/html/parser/HTMLEntityParser.cpp

    r140610 r140731  
    6969    }
    7070
    71     inline static void convertToUTF16(UChar32 value, StringBuilder& decodedEntity)
    72     {
    73         if (U_IS_BMP(value)) {
    74             UChar character = static_cast<UChar>(value);
    75             ASSERT(character == value);
    76             decodedEntity.append(character);
    77             return;
    78         }
    79         decodedEntity.append(U16_LEAD(value));
    80         decodedEntity.append(U16_TRAIL(value));
    81     }
    82 
    8371    inline static bool acceptMalformed() { return true; }
    8472
     
    126114            || !additionalAllowedCharacter
    127115            || !(isAlphaNumeric(cc) || cc == '=')) {
    128             convertToUTF16(entitySearch.mostRecentMatch()->firstValue, decodedEntity);
     116            decodedEntity.append(entitySearch.mostRecentMatch()->firstValue);
    129117            if (entitySearch.mostRecentMatch()->secondValue)
    130                 convertToUTF16(entitySearch.mostRecentMatch()->secondValue, decodedEntity);
     118                decodedEntity.append(entitySearch.mostRecentMatch()->secondValue);
    131119            return true;
    132120        }
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r138316 r140731  
    292292    mirroredCharacters.reserveCapacity(length);
    293293
    294     UChar32 character;
    295294    unsigned i = 0;
    296295    while (i < length) {
     296        UChar32 character;
    297297        U16_NEXT(characters, i, length, character);
    298         character = mirroredChar(character);
    299 
    300         if (U16_LENGTH(character) == 1)
    301             mirroredCharacters.append(static_cast<UChar>(character));
    302         else {
    303             mirroredCharacters.append(U16_LEAD(character));
    304             mirroredCharacters.append(U16_TRAIL(character));
    305         }
     298        mirroredCharacters.append(mirroredChar(character));
    306299    }
    307300
  • trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h

    r135802 r140731  
    129129            else if (cc == ';') {
    130130                source.advanceAndASSERT(cc);
    131                 ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
     131                decodedCharacter.append(ParserFunctions::legalEntityFor(result));
    132132                return true;
    133133            } else if (ParserFunctions::acceptMalformed()) {
    134                 ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
     134                decodedCharacter.append(ParserFunctions::legalEntityFor(result));
    135135                return true;
    136136            } else {
     
    145145            else if (cc == ';') {
    146146                source.advanceAndASSERT(cc);
    147                 ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
     147                decodedCharacter.append(ParserFunctions::legalEntityFor(result));
    148148                return true;
    149149            } else if (ParserFunctions::acceptMalformed()) {
    150                 ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
     150                decodedCharacter.append(ParserFunctions::legalEntityFor(result));
    151151                return true;
    152152            } else {
  • trunk/Tools/ChangeLog

    r140717 r140731  
     12013-01-24  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Abstract the logic for appending a UChar32 onto StringBuilder
     4        https://bugs.webkit.org/show_bug.cgi?id=107505
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
     9        (TestWebKitAPI::TEST): Added a simple test for appending UChar32.
     10
    1112013-01-24  Erik Arvidsson  <arv@chromium.org>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp

    r105639 r140731  
    3434namespace TestWebKitAPI {
    3535
    36 void expectBuilderContent(const char* expected, const StringBuilder& builder)
     36static void expectBuilderContent(const String& expected, const StringBuilder& builder)
    3737{
    3838    // Not using builder.toString() or builder.toStringPreserveCapacity() because they all
    3939    // change internal state of builder.
    40     EXPECT_EQ(String(expected), String(builder.characters(), builder.length()));
     40    EXPECT_EQ(expected, String(builder.characters(), builder.length()));
    4141}
    4242
     
    8686    builder2.append("abcd");
    8787    ASSERT_EQ(characters, builder2.characters());
     88
     89    // Test appending UChar32 characters to StringBuilder.
     90    StringBuilder builderForUChar32Append;
     91    UChar32 frakturAChar = 0x1D504;
     92    builderForUChar32Append.append(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
     93    ASSERT_EQ(2U, builderForUChar32Append.length());
     94    builderForUChar32Append.append(static_cast<UChar32>('A'));
     95    ASSERT_EQ(3U, builderForUChar32Append.length());
     96    const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), 'A' };
     97    expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builderForUChar32Append);
    8898}
    8999
Note: See TracChangeset for help on using the changeset viewer.