| 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..c0c96397ae3aa33d4d1ca7f33ed4cb88477e6869
|
| --- /dev/null
|
| +++ b/Source/core/css/CSSValueIDHelper.cpp
|
| @@ -0,0 +1,41 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// 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);
|
| +}
|
| +
|
| +}
|
|
|