Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Unified Diff: Source/core/css/CSSMarkup.cpp

Issue 884123006: Merge CSSMarkup and CSSOMUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSMarkup.h ('k') | Source/core/css/CSSOMUtils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSMarkup.cpp
diff --git a/Source/core/css/CSSMarkup.cpp b/Source/core/css/CSSMarkup.cpp
index 182a6049aaf829ce01f2d2acd621722cfd9c6600..c5326afa96418b42b3f9dff642fbb05c7018365b 100644
--- a/Source/core/css/CSSMarkup.cpp
+++ b/Source/core/css/CSSMarkup.cpp
@@ -29,6 +29,7 @@
#include "wtf/HexNumber.h"
#include "wtf/text/StringBuffer.h"
+#include "wtf/text/StringBuilder.h"
namespace blink {
@@ -186,4 +187,65 @@ String quoteCSSURLIfNeeded(const String& string)
return isCSSTokenizerURL(string) ? string : quoteCSSString(string);
}
+static void serializeCharacter(UChar32 c, StringBuilder& appendTo)
+{
+ appendTo.append('\\');
+ appendTo.append(c);
+}
+
+static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
+{
+ appendTo.append('\\');
+ appendUnsignedAsHex(c, appendTo, Lowercase);
+ appendTo.append(' ');
+}
+
+void serializeIdentifier(const String& identifier, StringBuilder& appendTo)
+{
+ bool isFirst = true;
+ bool isSecond = false;
+ bool isFirstCharHyphen = false;
+ unsigned index = 0;
+ while (index < identifier.length()) {
+ UChar32 c = identifier.characterStartingAt(index);
+ index += U16_LENGTH(c);
+
+ if (c <= 0x1f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
+ serializeCharacterAsCodePoint(c, appendTo);
+ 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))
+ appendTo.append(c);
+ else
+ serializeCharacter(c, appendTo);
+
+ if (isFirst) {
+ isFirst = false;
+ isSecond = true;
+ isFirstCharHyphen = (c == 0x2d);
+ } else if (isSecond) {
+ isSecond = false;
+ }
+ }
+}
+
+void serializeString(const String& string, StringBuilder& appendTo)
+{
+ appendTo.append('\"');
+
+ unsigned index = 0;
+ while (index < string.length()) {
+ UChar32 c = string.characterStartingAt(index);
+ index += U16_LENGTH(c);
+ if (c <= 0x1f)
+ serializeCharacterAsCodePoint(c, appendTo);
+ else if (c == 0x22 || c == 0x5c)
+ serializeCharacter(c, appendTo);
+ else
+ appendTo.append(c);
+ }
+
+ appendTo.append('\"');
+}
+
} // namespace blink
« no previous file with comments | « Source/core/css/CSSMarkup.h ('k') | Source/core/css/CSSOMUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698