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

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

Issue 171383002: A thread-safe Media Query Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Another attempt to fix Android build issues Created 6 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
Index: Source/core/css/CSSValueIDHelper.cpp
diff --git a/Source/core/css/CSSValueIDHelper.cpp b/Source/core/css/CSSValueIDHelper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0b3283cad225daf5e14bac650429c468ba6a2fba
--- /dev/null
+++ b/Source/core/css/CSSValueIDHelper.cpp
@@ -0,0 +1,42 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+//
abarth-chromium 2014/03/01 07:28:25 ditto
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/css/CSSValueIDHelper.h"
+
+#include "core/css/CSSParserValues.h"
+#include "core/css/HashTools.h"
+
+namespace WebCore {
+
+template <typename CharacterType>
+static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
+{
+ char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character
+
+ for (unsigned i = 0; i != length; ++i) {
+ CharacterType c = valueKeyword[i];
+ if (!c || c >= 0x7F)
+ return CSSValueInvalid; // illegal character
+ buffer[i] = WTF::toASCIILower(c);
+ }
+ buffer[length] = '\0';
+
+ const Value* hashTableEntry = findValue(buffer, length);
+ return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSValueInvalid;
+}
+
+CSSValueID cssValueKeywordID(const CSSParserString& string)
+{
+ unsigned length = string.length();
+ if (!length)
+ return CSSValueInvalid;
+ if (length > maxCSSValueKeywordLength)
+ return CSSValueInvalid;
+
+ return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : cssValueKeywordID(string.characters16(), length);
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698