Diff
Modified: trunk/Source/WTF/ChangeLog (140730 => 140731)
--- trunk/Source/WTF/ChangeLog 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WTF/ChangeLog 2013-01-24 23:01:06 UTC (rev 140731)
@@ -1,3 +1,13 @@
+2013-01-24 Martin Robinson <[email protected]>
+
+ Abstract the logic for appending a UChar32 onto StringBuilder
+ https://bugs.webkit.org/show_bug.cgi?id=107505
+
+ Reviewed by Darin Adler.
+
+ * wtf/text/StringBuilder.h:
+ (WTF::StringBuilder::append): Added a method for appending a UChar32 to a StringBuilder.
+
2013-01-24 Brent Fulgham <[email protected]>
Stipulate build order between WTFGenerated and WTF
Modified: trunk/Source/WTF/wtf/text/StringBuilder.h (140730 => 140731)
--- trunk/Source/WTF/wtf/text/StringBuilder.h 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WTF/wtf/text/StringBuilder.h 2013-01-24 23:01:06 UTC (rev 140731)
@@ -141,6 +141,16 @@
append(static_cast<LChar>(c));
}
+ void append(UChar32 c)
+ {
+ if (U_IS_BMP(c)) {
+ append(static_cast<UChar>(c));
+ return;
+ }
+ append(U16_LEAD(c));
+ append(U16_TRAIL(c));
+ }
+
template<unsigned charactersCount>
ALWAYS_INLINE void appendLiteral(const char (&characters)[charactersCount]) { append(characters, charactersCount - 1); }
Modified: trunk/Source/WebCore/ChangeLog (140730 => 140731)
--- trunk/Source/WebCore/ChangeLog 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WebCore/ChangeLog 2013-01-24 23:01:06 UTC (rev 140731)
@@ -1,3 +1,23 @@
+2013-01-24 Martin Robinson <[email protected]>
+
+ Abstract the logic for appending a UChar32 onto StringBuilder
+ https://bugs.webkit.org/show_bug.cgi?id=107505
+
+ Reviewed by Darin Adler.
+
+ * 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.
+
2013-01-24 Kentaro Hara <[email protected]>
[V8] Pass an Isolate to GetTemplate() in v8/*.cpp
Modified: trunk/Source/WebCore/css/CSSOMUtils.cpp (140730 => 140731)
--- trunk/Source/WebCore/css/CSSOMUtils.cpp 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WebCore/css/CSSOMUtils.cpp 2013-01-24 23:01:06 UTC (rev 140731)
@@ -36,20 +36,10 @@
namespace WebCore {
-static void appendCharacter(UChar32 c, StringBuilder& appendTo)
-{
- if (U16_LENGTH(c) == 1)
- appendTo.append(static_cast<UChar>(c));
- else {
- appendTo.append(U16_LEAD(c));
- appendTo.append(U16_TRAIL(c));
- }
-}
-
void serializeCharacter(UChar32 c, StringBuilder& appendTo)
{
appendTo.append('\\');
- appendCharacter(c, appendTo);
+ appendTo.append(c);
}
void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
@@ -81,7 +71,7 @@
else if (c == 0x2d && isSecond && isFirstCharHyphen)
serializeCharacter(c, appendTo);
else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
- appendCharacter(c, appendTo);
+ appendTo.append(c);
else
serializeCharacter(c, appendTo);
@@ -115,7 +105,7 @@
else if (c == 0x22 || c == 0x5c)
serializeCharacter(c, appendTo);
else
- appendCharacter(c, appendTo);
+ appendTo.append(c);
}
appendTo.append('\"');
Modified: trunk/Source/WebCore/html/parser/HTMLEntityParser.cpp (140730 => 140731)
--- trunk/Source/WebCore/html/parser/HTMLEntityParser.cpp 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WebCore/html/parser/HTMLEntityParser.cpp 2013-01-24 23:01:06 UTC (rev 140731)
@@ -68,18 +68,6 @@
return value;
}
- inline static void convertToUTF16(UChar32 value, StringBuilder& decodedEntity)
- {
- if (U_IS_BMP(value)) {
- UChar character = static_cast<UChar>(value);
- ASSERT(character == value);
- decodedEntity.append(character);
- return;
- }
- decodedEntity.append(U16_LEAD(value));
- decodedEntity.append(U16_TRAIL(value));
- }
-
inline static bool acceptMalformed() { return true; }
inline static bool consumeNamedEntity(SegmentedString& source, StringBuilder& decodedEntity, bool& notEnoughCharacters, UChar additionalAllowedCharacter, UChar& cc)
@@ -125,9 +113,9 @@
if (entitySearch.mostRecentMatch()->lastCharacter() == ';'
|| !additionalAllowedCharacter
|| !(isAlphaNumeric(cc) || cc == '=')) {
- convertToUTF16(entitySearch.mostRecentMatch()->firstValue, decodedEntity);
+ decodedEntity.append(entitySearch.mostRecentMatch()->firstValue);
if (entitySearch.mostRecentMatch()->secondValue)
- convertToUTF16(entitySearch.mostRecentMatch()->secondValue, decodedEntity);
+ decodedEntity.append(entitySearch.mostRecentMatch()->secondValue);
return true;
}
unconsumeCharacters(source, consumedCharacters);
Modified: trunk/Source/WebCore/svg/SVGFontData.cpp (140730 => 140731)
--- trunk/Source/WebCore/svg/SVGFontData.cpp 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WebCore/svg/SVGFontData.cpp 2013-01-24 23:01:06 UTC (rev 140731)
@@ -291,18 +291,11 @@
StringBuilder mirroredCharacters;
mirroredCharacters.reserveCapacity(length);
- UChar32 character;
unsigned i = 0;
while (i < length) {
+ UChar32 character;
U16_NEXT(characters, i, length, character);
- character = mirroredChar(character);
-
- if (U16_LENGTH(character) == 1)
- mirroredCharacters.append(static_cast<UChar>(character));
- else {
- mirroredCharacters.append(U16_LEAD(character));
- mirroredCharacters.append(U16_TRAIL(character));
- }
+ mirroredCharacters.append(mirroredChar(character));
}
return mirroredCharacters.toString();
Modified: trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h (140730 => 140731)
--- trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Source/WebCore/xml/parser/CharacterReferenceParserInlines.h 2013-01-24 23:01:06 UTC (rev 140731)
@@ -128,10 +128,10 @@
result = result * 16 + 10 + cc - 'A';
else if (cc == ';') {
source.advanceAndASSERT(cc);
- ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
+ decodedCharacter.append(ParserFunctions::legalEntityFor(result));
return true;
} else if (ParserFunctions::acceptMalformed()) {
- ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
+ decodedCharacter.append(ParserFunctions::legalEntityFor(result));
return true;
} else {
unconsumeCharacters(source, consumedCharacters);
@@ -144,10 +144,10 @@
result = result * 10 + cc - '0';
else if (cc == ';') {
source.advanceAndASSERT(cc);
- ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
+ decodedCharacter.append(ParserFunctions::legalEntityFor(result));
return true;
} else if (ParserFunctions::acceptMalformed()) {
- ParserFunctions::convertToUTF16(ParserFunctions::legalEntityFor(result), decodedCharacter);
+ decodedCharacter.append(ParserFunctions::legalEntityFor(result));
return true;
} else {
unconsumeCharacters(source, consumedCharacters);
Modified: trunk/Tools/ChangeLog (140730 => 140731)
--- trunk/Tools/ChangeLog 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Tools/ChangeLog 2013-01-24 23:01:06 UTC (rev 140731)
@@ -1,3 +1,13 @@
+2013-01-24 Martin Robinson <[email protected]>
+
+ Abstract the logic for appending a UChar32 onto StringBuilder
+ https://bugs.webkit.org/show_bug.cgi?id=107505
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
+ (TestWebKitAPI::TEST): Added a simple test for appending UChar32.
+
2013-01-24 Erik Arvidsson <[email protected]>
Unreviewed, rolling out r140703.
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp (140730 => 140731)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp 2013-01-24 22:59:38 UTC (rev 140730)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp 2013-01-24 23:01:06 UTC (rev 140731)
@@ -33,11 +33,11 @@
namespace TestWebKitAPI {
-void expectBuilderContent(const char* expected, const StringBuilder& builder)
+static void expectBuilderContent(const String& expected, const StringBuilder& builder)
{
// Not using builder.toString() or builder.toStringPreserveCapacity() because they all
// change internal state of builder.
- EXPECT_EQ(String(expected), String(builder.characters(), builder.length()));
+ EXPECT_EQ(expected, String(builder.characters(), builder.length()));
}
void expectEmpty(const StringBuilder& builder)
@@ -85,6 +85,16 @@
builder2.toStringPreserveCapacity(); // Test after reifyString with buffer preserved.
builder2.append("abcd");
ASSERT_EQ(characters, builder2.characters());
+
+ // Test appending UChar32 characters to StringBuilder.
+ StringBuilder builderForUChar32Append;
+ UChar32 frakturAChar = 0x1D504;
+ builderForUChar32Append.append(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
+ ASSERT_EQ(2U, builderForUChar32Append.length());
+ builderForUChar32Append.append(static_cast<UChar32>('A'));
+ ASSERT_EQ(3U, builderForUChar32Append.length());
+ const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), 'A' };
+ expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builderForUChar32Append);
}
TEST(StringBuilderTest, ToString)