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

Side by Side 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: Generate strings with make_names Created 6 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/css/CSSValueIDHelper.h"
7
8 #include "core/css/CSSParserValues.h"
9 #include "core/css/HashTools.h"
10
11 namespace WebCore {
12
13 template <typename CharacterType>
14 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
15 {
16 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character
17
18 for (unsigned i = 0; i != length; ++i) {
19 CharacterType c = valueKeyword[i];
20 if (!c || c >= 0x7F)
21 return CSSValueInvalid; // illegal character
22 buffer[i] = WTF::toASCIILower(c);
23 }
24 buffer[length] = '\0';
25
26 const Value* hashTableEntry = findValue(buffer, length);
27 return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSVal ueInvalid;
28 }
29
30 CSSValueID cssValueKeywordID(const CSSParserString& string)
31 {
32 unsigned length = string.length();
33 if (!length)
34 return CSSValueInvalid;
35 if (length > maxCSSValueKeywordLength)
36 return CSSValueInvalid;
37
38 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c ssValueKeywordID(string.characters16(), length);
39 }
40
41 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698