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

Side by Side Diff: Source/core/css/parser/CSSParserString.h

Issue 1188513005: Move CSSParserString out of CSSParserValues.h (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Change includes to use CSSParserString.h Created 5 years, 6 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
« no previous file with comments | « Source/core/css/parser/CSSParserFastPaths.cpp ('k') | Source/core/css/parser/CSSParserToken.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef CSSParserString_h
22 #define CSSParserString_h
23
24 #include "wtf/text/AtomicString.h"
25 #include "wtf/text/WTFString.h"
26
27 namespace blink {
28
29 struct CSSParserString {
30 void init(const LChar* characters, unsigned length)
31 {
32 m_data.characters8 = characters;
33 m_length = length;
34 m_is8Bit = true;
35 }
36
37 void init(const UChar* characters, unsigned length)
38 {
39 m_data.characters16 = characters;
40 m_length = length;
41 m_is8Bit = false;
42 }
43
44 void initRaw(const void* charactersRaw, unsigned length, bool is8Bit)
45 {
46 m_data.charactersRaw = charactersRaw;
47 m_length = length;
48 m_is8Bit = is8Bit;
49 }
50
51 void init(const String& string)
52 {
53 m_length = string.length();
54 if (string.isNull()) {
55 m_data.characters8 = 0;
56 m_is8Bit = true;
57 return;
58 }
59 if (string.is8Bit()) {
60 m_data.characters8 = const_cast<LChar*>(string.characters8());
61 m_is8Bit = true;
62 } else {
63 m_data.characters16 = const_cast<UChar*>(string.characters16());
64 m_is8Bit = false;
65 }
66 }
67
68 bool is8Bit() const { return m_is8Bit; }
69 const LChar* characters8() const { ASSERT(is8Bit()); return m_data.character s8; }
70 const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.charact ers16; }
71
72 unsigned length() const { return m_length; }
73
74 UChar operator[](unsigned i) const
75 {
76 ASSERT_WITH_SECURITY_IMPLICATION(i < m_length);
77 if (is8Bit())
78 return m_data.characters8[i];
79 return m_data.characters16[i];
80 }
81
82 bool equalIgnoringCase(const char* str) const
83 {
84 bool match = is8Bit() ? WTF::equalIgnoringCase(str, characters8(), lengt h()) : WTF::equalIgnoringCase(str, characters16(), length());
85 if (!match)
86 return false;
87 ASSERT(strlen(str) >= length());
88 return str[length()] == '\0';
89 }
90
91 operator String() const { return is8Bit() ? String(m_data.characters8, m_len gth) : StringImpl::create8BitIfPossible(m_data.characters16, m_length); }
92 operator AtomicString() const { return is8Bit() ? AtomicString(m_data.charac ters8, m_length) : AtomicString(m_data.characters16, m_length); }
93
94 union {
95 const LChar* characters8;
96 const UChar* characters16;
97 const void* charactersRaw;
98 } m_data;
99 unsigned m_length;
100 bool m_is8Bit;
101 };
102
103 }
104
105 #endif
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSParserFastPaths.cpp ('k') | Source/core/css/parser/CSSParserToken.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698