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); |
+} |
+ |
+} |