| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (numLeadingSpaces == length) | 54 if (numLeadingSpaces == length) |
| 55 return string.isNull() ? string : emptyAtom.getString(); | 55 return string.isNull() ? string : emptyAtom.getString(); |
| 56 | 56 |
| 57 for (; numTrailingSpaces < length; ++numTrailingSpaces) { | 57 for (; numTrailingSpaces < length; ++numTrailingSpaces) { |
| 58 if (isNotHTMLSpace<CharType>(characters[length - numTrailingSpaces - 1])) | 58 if (isNotHTMLSpace<CharType>(characters[length - numTrailingSpaces - 1])) |
| 59 break; | 59 break; |
| 60 } | 60 } |
| 61 | 61 |
| 62 ASSERT(numLeadingSpaces + numTrailingSpaces < length); | 62 DCHECK_LT(numLeadingSpaces + numTrailingSpaces, length); |
| 63 | 63 |
| 64 if (!(numLeadingSpaces | numTrailingSpaces)) | 64 if (!(numLeadingSpaces | numTrailingSpaces)) |
| 65 return string; | 65 return string; |
| 66 | 66 |
| 67 return string.substring(numLeadingSpaces, | 67 return string.substring(numLeadingSpaces, |
| 68 length - (numLeadingSpaces + numTrailingSpaces)); | 68 length - (numLeadingSpaces + numTrailingSpaces)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 String stripLeadingAndTrailingHTMLSpaces(const String& string) { | 71 String stripLeadingAndTrailingHTMLSpaces(const String& string) { |
| 72 unsigned length = string.length(); | 72 unsigned length = string.length(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Step 4 | 166 // Step 4 |
| 167 while (position < end) { | 167 while (position < end) { |
| 168 if (!isHTMLSpace<CharacterType>(*position)) | 168 if (!isHTMLSpace<CharacterType>(*position)) |
| 169 break; | 169 break; |
| 170 ++position; | 170 ++position; |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Step 5 | 173 // Step 5 |
| 174 if (position == end) | 174 if (position == end) |
| 175 return false; | 175 return false; |
| 176 ASSERT(position < end); | 176 DCHECK_LT(position, end); |
| 177 | 177 |
| 178 // Step 6 | 178 // Step 6 |
| 179 if (*position == '-') { | 179 if (*position == '-') { |
| 180 isNegative = true; | 180 isNegative = true; |
| 181 ++position; | 181 ++position; |
| 182 } else if (*position == '+') | 182 } else if (*position == '+') |
| 183 ++position; | 183 ++position; |
| 184 if (position == end) | 184 if (position == end) |
| 185 return false; | 185 return false; |
| 186 ASSERT(position < end); | 186 DCHECK_LT(position, end); |
| 187 | 187 |
| 188 // Step 7 | 188 // Step 7 |
| 189 if (!isASCIIDigit(*position)) | 189 if (!isASCIIDigit(*position)) |
| 190 return false; | 190 return false; |
| 191 | 191 |
| 192 // Step 8 | 192 // Step 8 |
| 193 static const int intMax = std::numeric_limits<int>::max(); | 193 static const int intMax = std::numeric_limits<int>::max(); |
| 194 const int base = 10; | 194 const int base = 10; |
| 195 const int maxMultiplier = intMax / base; | 195 const int maxMultiplier = intMax / base; |
| 196 | 196 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Step 4: Skip whitespace. | 240 // Step 4: Skip whitespace. |
| 241 while (position < end) { | 241 while (position < end) { |
| 242 if (!isHTMLSpace<CharacterType>(*position)) | 242 if (!isHTMLSpace<CharacterType>(*position)) |
| 243 break; | 243 break; |
| 244 ++position; | 244 ++position; |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Step 5: If position is past the end of input, return an error. | 247 // Step 5: If position is past the end of input, return an error. |
| 248 if (position == end) | 248 if (position == end) |
| 249 return false; | 249 return false; |
| 250 ASSERT(position < end); | 250 DCHECK_LT(position, end); |
| 251 | 251 |
| 252 // Step 6: If the character indicated by position (the first character) is a | 252 // Step 6: If the character indicated by position (the first character) is a |
| 253 // U+002D HYPHEN-MINUS character (-), ... | 253 // U+002D HYPHEN-MINUS character (-), ... |
| 254 if (*position == '-') { | 254 if (*position == '-') { |
| 255 sign = -1; | 255 sign = -1; |
| 256 ++position; | 256 ++position; |
| 257 } else if (*position == '+') { | 257 } else if (*position == '+') { |
| 258 ++position; | 258 ++position; |
| 259 } | 259 } |
| 260 | 260 |
| 261 if (position == end) | 261 if (position == end) |
| 262 return false; | 262 return false; |
| 263 ASSERT(position < end); | 263 DCHECK_LT(position, end); |
| 264 | 264 |
| 265 // Step 7: If the character indicated by position is not an ASCII digit, | 265 // Step 7: If the character indicated by position is not an ASCII digit, |
| 266 // then return an error. | 266 // then return an error. |
| 267 if (!isASCIIDigit(*position)) | 267 if (!isASCIIDigit(*position)) |
| 268 return false; | 268 return false; |
| 269 | 269 |
| 270 // Step 8: Collect a sequence of characters ... | 270 // Step 8: Collect a sequence of characters ... |
| 271 StringBuilder digits; | 271 StringBuilder digits; |
| 272 while (position < end) { | 272 while (position < end) { |
| 273 if (!isASCIIDigit(*position)) | 273 if (!isASCIIDigit(*position)) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 continue; | 369 continue; |
| 370 | 370 |
| 371 ++pos; | 371 ++pos; |
| 372 | 372 |
| 373 while (pos < length && value[pos] <= ' ') | 373 while (pos < length && value[pos] <= ' ') |
| 374 ++pos; | 374 ++pos; |
| 375 | 375 |
| 376 char quoteMark = 0; | 376 char quoteMark = 0; |
| 377 if (pos < length && (value[pos] == '"' || value[pos] == '\'')) { | 377 if (pos < length && (value[pos] == '"' || value[pos] == '\'')) { |
| 378 quoteMark = static_cast<char>(value[pos++]); | 378 quoteMark = static_cast<char>(value[pos++]); |
| 379 ASSERT(!(quoteMark & 0x80)); | 379 DCHECK(!(quoteMark & 0x80)); |
| 380 } | 380 } |
| 381 | 381 |
| 382 if (pos == length) | 382 if (pos == length) |
| 383 break; | 383 break; |
| 384 | 384 |
| 385 unsigned end = pos; | 385 unsigned end = pos; |
| 386 while (end < length && | 386 while (end < length && |
| 387 ((quoteMark && value[end] != quoteMark) || | 387 ((quoteMark && value[end] != quoteMark) || |
| 388 (!quoteMark && value[end] > ' ' && value[end] != '"' && | 388 (!quoteMark && value[end] > ' ' && value[end] != '"' && |
| 389 value[end] != '\'' && value[end] != ';'))) | 389 value[end] != '\'' && value[end] != ';'))) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 454 |
| 455 template <typename CharType> | 455 template <typename CharType> |
| 456 inline StringImpl* findStringIfStatic(const CharType* characters, | 456 inline StringImpl* findStringIfStatic(const CharType* characters, |
| 457 unsigned length) { | 457 unsigned length) { |
| 458 // We don't need to try hashing if we know the string is too long. | 458 // We don't need to try hashing if we know the string is too long. |
| 459 if (length > StringImpl::highestStaticStringLength()) | 459 if (length > StringImpl::highestStaticStringLength()) |
| 460 return nullptr; | 460 return nullptr; |
| 461 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. | 461 // computeHashAndMaskTop8Bits is the function StringImpl::hash() uses. |
| 462 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length); | 462 unsigned hash = StringHasher::computeHashAndMaskTop8Bits(characters, length); |
| 463 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); | 463 const WTF::StaticStringsTable& table = StringImpl::allStaticStrings(); |
| 464 ASSERT(!table.isEmpty()); | 464 DCHECK(!table.isEmpty()); |
| 465 | 465 |
| 466 WTF::StaticStringsTable::const_iterator it = table.find(hash); | 466 WTF::StaticStringsTable::const_iterator it = table.find(hash); |
| 467 if (it == table.end()) | 467 if (it == table.end()) |
| 468 return nullptr; | 468 return nullptr; |
| 469 // It's possible to have hash collisions between arbitrary strings and known | 469 // It's possible to have hash collisions between arbitrary strings and known |
| 470 // identifiers (e.g. "bvvfg" collides with "script"). However ASSERTs in | 470 // identifiers (e.g. "bvvfg" collides with "script"). However ASSERTs in |
| 471 // StringImpl::createStatic guard against there ever being collisions between | 471 // StringImpl::createStatic guard against there ever being collisions between |
| 472 // static strings. | 472 // static strings. |
| 473 if (!equal(it->value, characters, length)) | 473 if (!equal(it->value, characters, length)) |
| 474 return nullptr; | 474 return nullptr; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 492 string = StringImpl::create8BitIfPossible(characters, size); | 492 string = StringImpl::create8BitIfPossible(characters, size); |
| 493 else if (width == Force8Bit) | 493 else if (width == Force8Bit) |
| 494 string = String::make8BitFrom16BitSource(characters, size); | 494 string = String::make8BitFrom16BitSource(characters, size); |
| 495 else | 495 else |
| 496 string = String(characters, size); | 496 string = String(characters, size); |
| 497 | 497 |
| 498 return string; | 498 return string; |
| 499 } | 499 } |
| 500 | 500 |
| 501 } // namespace blink | 501 } // namespace blink |
| OLD | NEW |