| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 {% for namespace in config.protocol.namespace %} | 5 {% for namespace in config.protocol.namespace %} |
| 6 namespace {{namespace}} { | 6 namespace {{namespace}} { |
| 7 {% endfor %} | 7 {% endfor %} |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 DCHECK(false); | 330 DCHECK(false); |
| 331 return 0; | 331 return 0; |
| 332 } | 332 } |
| 333 | 333 |
| 334 template<typename Char> | 334 template<typename Char> |
| 335 bool decodeString(const Char* start, const Char* end, StringBuilder* output) | 335 bool decodeString(const Char* start, const Char* end, StringBuilder* output) |
| 336 { | 336 { |
| 337 while (start < end) { | 337 while (start < end) { |
| 338 uint16_t c = *start++; | 338 uint16_t c = *start++; |
| 339 if ('\\' != c) { | 339 if ('\\' != c) { |
| 340 output->append(c); | 340 StringUtil::builderAppend(*output, c); |
| 341 continue; | 341 continue; |
| 342 } | 342 } |
| 343 if (start == end) | 343 if (start == end) |
| 344 return false; | 344 return false; |
| 345 c = *start++; | 345 c = *start++; |
| 346 | 346 |
| 347 if (c == 'x') { | 347 if (c == 'x') { |
| 348 // \x is not supported. | 348 // \x is not supported. |
| 349 return false; | 349 return false; |
| 350 } | 350 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 375 case 'u': | 375 case 'u': |
| 376 c = (hexToInt(*start) << 12) + | 376 c = (hexToInt(*start) << 12) + |
| 377 (hexToInt(*(start + 1)) << 8) + | 377 (hexToInt(*(start + 1)) << 8) + |
| 378 (hexToInt(*(start + 2)) << 4) + | 378 (hexToInt(*(start + 2)) << 4) + |
| 379 hexToInt(*(start + 3)); | 379 hexToInt(*(start + 3)); |
| 380 start += 4; | 380 start += 4; |
| 381 break; | 381 break; |
| 382 default: | 382 default: |
| 383 return false; | 383 return false; |
| 384 } | 384 } |
| 385 output->append(c); | 385 StringUtil::builderAppend(*output, c); |
| 386 } | 386 } |
| 387 return true; | 387 return true; |
| 388 } | 388 } |
| 389 | 389 |
| 390 template<typename Char> | 390 template<typename Char> |
| 391 bool decodeString(const Char* start, const Char* end, String* output) | 391 bool decodeString(const Char* start, const Char* end, String* output) |
| 392 { | 392 { |
| 393 if (start == end) { | 393 if (start == end) { |
| 394 *output = ""; | 394 *output = ""; |
| 395 return true; | 395 return true; |
| 396 } | 396 } |
| 397 if (start > end) | 397 if (start > end) |
| 398 return false; | 398 return false; |
| 399 StringBuilder buffer; | 399 StringBuilder buffer; |
| 400 StringUtil::builderReserve(buffer, end - start); | 400 StringUtil::builderReserve(buffer, end - start); |
| 401 if (!decodeString(start, end, &buffer)) | 401 if (!decodeString(start, end, &buffer)) |
| 402 return false; | 402 return false; |
| 403 *output = buffer.toString(); | 403 *output = StringUtil::builderToString(buffer); |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 template<typename Char> | 407 template<typename Char> |
| 408 std::unique_ptr<Value> buildValue(const Char* start, const Char* end, const Char
** valueTokenEnd, int depth) | 408 std::unique_ptr<Value> buildValue(const Char* start, const Char* end, const Char
** valueTokenEnd, int depth) |
| 409 { | 409 { |
| 410 if (depth > stackLimit) | 410 if (depth > stackLimit) |
| 411 return nullptr; | 411 return nullptr; |
| 412 | 412 |
| 413 std::unique_ptr<Value> result; | 413 std::unique_ptr<Value> result; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 544 } |
| 545 | 545 |
| 546 std::unique_ptr<Value> parseJSONCharacters(const uint8_t* characters, unsigned l
ength) | 546 std::unique_ptr<Value> parseJSONCharacters(const uint8_t* characters, unsigned l
ength) |
| 547 { | 547 { |
| 548 return parseJSONInternal<uint8_t>(characters, length); | 548 return parseJSONInternal<uint8_t>(characters, length); |
| 549 } | 549 } |
| 550 | 550 |
| 551 {% for namespace in config.protocol.namespace %} | 551 {% for namespace in config.protocol.namespace %} |
| 552 } // namespace {{namespace}} | 552 } // namespace {{namespace}} |
| 553 {% endfor %} | 553 {% endfor %} |
| OLD | NEW |