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

Side by Side Diff: Source/core/css/CSSMarkup.cpp

Issue 884123006: Merge CSSMarkup and CSSOMUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSMarkup.h ('k') | Source/core/css/CSSOMUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 11 matching lines...) Expand all
22 * along with this library; see the file COPYING.LIB. If not, write to 22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA. 24 * Boston, MA 02110-1301, USA.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/css/CSSMarkup.h" 28 #include "core/css/CSSMarkup.h"
29 29
30 #include "wtf/HexNumber.h" 30 #include "wtf/HexNumber.h"
31 #include "wtf/text/StringBuffer.h" 31 #include "wtf/text/StringBuffer.h"
32 #include "wtf/text/StringBuilder.h"
32 33
33 namespace blink { 34 namespace blink {
34 35
35 template <typename CharacterType> 36 template <typename CharacterType>
36 static inline bool isCSSTokenizerIdentifier(const CharacterType* characters, uns igned length) 37 static inline bool isCSSTokenizerIdentifier(const CharacterType* characters, uns igned length)
37 { 38 {
38 const CharacterType* end = characters + length; 39 const CharacterType* end = characters + length;
39 40
40 // -? 41 // -?
41 if (characters != end && characters[0] == '-') 42 if (characters != end && characters[0] == '-')
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 String quoteCSSStringIfNeeded(const String& string) 180 String quoteCSSStringIfNeeded(const String& string)
180 { 181 {
181 return isCSSTokenizerIdentifier(string) ? string : quoteCSSString(string); 182 return isCSSTokenizerIdentifier(string) ? string : quoteCSSString(string);
182 } 183 }
183 184
184 String quoteCSSURLIfNeeded(const String& string) 185 String quoteCSSURLIfNeeded(const String& string)
185 { 186 {
186 return isCSSTokenizerURL(string) ? string : quoteCSSString(string); 187 return isCSSTokenizerURL(string) ? string : quoteCSSString(string);
187 } 188 }
188 189
190 static void serializeCharacter(UChar32 c, StringBuilder& appendTo)
191 {
192 appendTo.append('\\');
193 appendTo.append(c);
194 }
195
196 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
197 {
198 appendTo.append('\\');
199 appendUnsignedAsHex(c, appendTo, Lowercase);
200 appendTo.append(' ');
201 }
202
203 void serializeIdentifier(const String& identifier, StringBuilder& appendTo)
204 {
205 bool isFirst = true;
206 bool isSecond = false;
207 bool isFirstCharHyphen = false;
208 unsigned index = 0;
209 while (index < identifier.length()) {
210 UChar32 c = identifier.characterStartingAt(index);
211 index += U16_LENGTH(c);
212
213 if (c <= 0x1f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isF irstCharHyphen))))
214 serializeCharacterAsCodePoint(c, appendTo);
215 else if (c == 0x2d && isSecond && isFirstCharHyphen)
216 serializeCharacter(c, appendTo);
217 else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
218 appendTo.append(c);
219 else
220 serializeCharacter(c, appendTo);
221
222 if (isFirst) {
223 isFirst = false;
224 isSecond = true;
225 isFirstCharHyphen = (c == 0x2d);
226 } else if (isSecond) {
227 isSecond = false;
228 }
229 }
230 }
231
232 void serializeString(const String& string, StringBuilder& appendTo)
233 {
234 appendTo.append('\"');
235
236 unsigned index = 0;
237 while (index < string.length()) {
238 UChar32 c = string.characterStartingAt(index);
239 index += U16_LENGTH(c);
240 if (c <= 0x1f)
241 serializeCharacterAsCodePoint(c, appendTo);
242 else if (c == 0x22 || c == 0x5c)
243 serializeCharacter(c, appendTo);
244 else
245 appendTo.append(c);
246 }
247
248 appendTo.append('\"');
249 }
250
189 } // namespace blink 251 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/CSSMarkup.h ('k') | Source/core/css/CSSOMUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698