| OLD | NEW |
| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 appendTo.append(c); | 193 appendTo.append(c); |
| 194 } | 194 } |
| 195 | 195 |
| 196 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo) | 196 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo) |
| 197 { | 197 { |
| 198 appendTo.append('\\'); | 198 appendTo.append('\\'); |
| 199 appendUnsignedAsHex(c, appendTo, Lowercase); | 199 appendUnsignedAsHex(c, appendTo, Lowercase); |
| 200 appendTo.append(' '); | 200 appendTo.append(' '); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void serializeIdentifier(const String& identifier, StringBuilder& appendTo) | 203 bool serializeIdentifier(const String& identifier, StringBuilder& appendTo) |
| 204 { | 204 { |
| 205 bool isFirst = true; | 205 bool isFirst = true; |
| 206 bool isSecond = false; | 206 bool isSecond = false; |
| 207 bool isFirstCharHyphen = false; | 207 bool isFirstCharHyphen = false; |
| 208 unsigned index = 0; | 208 unsigned index = 0; |
| 209 while (index < identifier.length()) { | 209 while (index < identifier.length()) { |
| 210 UChar32 c = identifier.characterStartingAt(index); | 210 UChar32 c = identifier.characterStartingAt(index); |
| 211 if (c == 0) { |
| 212 // Check for lone surrogate which characterStartingAt does not retur
n. |
| 213 c = identifier[index]; |
| 214 if (c == 0) |
| 215 return false; |
| 216 } |
| 217 |
| 211 index += U16_LENGTH(c); | 218 index += U16_LENGTH(c); |
| 212 | 219 |
| 213 if (c <= 0x1f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isF
irstCharHyphen)))) | 220 if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst || (is
Second && isFirstCharHyphen)))) |
| 214 serializeCharacterAsCodePoint(c, appendTo); | 221 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)) | 222 else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39)
|| (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a)) |
| 218 appendTo.append(c); | 223 appendTo.append(c); |
| 219 else | 224 else |
| 220 serializeCharacter(c, appendTo); | 225 serializeCharacter(c, appendTo); |
| 221 | 226 |
| 222 if (isFirst) { | 227 if (isFirst) { |
| 223 isFirst = false; | 228 isFirst = false; |
| 224 isSecond = true; | 229 isSecond = true; |
| 225 isFirstCharHyphen = (c == 0x2d); | 230 isFirstCharHyphen = (c == 0x2d); |
| 226 } else if (isSecond) { | 231 } else if (isSecond) { |
| 227 isSecond = false; | 232 isSecond = false; |
| 228 } | 233 } |
| 229 } | 234 } |
| 235 return true; |
| 230 } | 236 } |
| 231 | 237 |
| 232 void serializeString(const String& string, StringBuilder& appendTo) | 238 void serializeString(const String& string, StringBuilder& appendTo) |
| 233 { | 239 { |
| 234 appendTo.append('\"'); | 240 appendTo.append('\"'); |
| 235 | 241 |
| 236 unsigned index = 0; | 242 unsigned index = 0; |
| 237 while (index < string.length()) { | 243 while (index < string.length()) { |
| 238 UChar32 c = string.characterStartingAt(index); | 244 UChar32 c = string.characterStartingAt(index); |
| 239 index += U16_LENGTH(c); | 245 index += U16_LENGTH(c); |
| 240 if (c <= 0x1f) | 246 if (c <= 0x1f) |
| 241 serializeCharacterAsCodePoint(c, appendTo); | 247 serializeCharacterAsCodePoint(c, appendTo); |
| 242 else if (c == 0x22 || c == 0x5c) | 248 else if (c == 0x22 || c == 0x5c) |
| 243 serializeCharacter(c, appendTo); | 249 serializeCharacter(c, appendTo); |
| 244 else | 250 else |
| 245 appendTo.append(c); | 251 appendTo.append(c); |
| 246 } | 252 } |
| 247 | 253 |
| 248 appendTo.append('\"'); | 254 appendTo.append('\"'); |
| 249 } | 255 } |
| 250 | 256 |
| 251 String serializeString(const String& string) | 257 String serializeString(const String& string) |
| 252 { | 258 { |
| 253 StringBuilder builder; | 259 StringBuilder builder; |
| 254 serializeString(string, builder); | 260 serializeString(string, builder); |
| 255 return builder.toString(); | 261 return builder.toString(); |
| 256 } | 262 } |
| 257 | 263 |
| 258 } // namespace blink | 264 } // namespace blink |
| OLD | NEW |