OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/json/json_parser.h" | 5 #include "base/json/json_parser.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); | 337 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); |
338 return nullptr; | 338 return nullptr; |
339 } | 339 } |
340 | 340 |
341 StackMarker depth_check(&stack_depth_); | 341 StackMarker depth_check(&stack_depth_); |
342 if (depth_check.IsTooDeep()) { | 342 if (depth_check.IsTooDeep()) { |
343 ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1); | 343 ReportError(JSONReader::JSON_TOO_MUCH_NESTING, 1); |
344 return nullptr; | 344 return nullptr; |
345 } | 345 } |
346 | 346 |
347 std::vector<Value::DictStorage::value_type> dict_storage; | 347 std::unique_ptr<DictionaryValue> dict(new DictionaryValue); |
348 | 348 |
349 NextChar(); | 349 NextChar(); |
350 Token token = GetNextToken(); | 350 Token token = GetNextToken(); |
351 while (token != T_OBJECT_END) { | 351 while (token != T_OBJECT_END) { |
352 if (token != T_STRING) { | 352 if (token != T_STRING) { |
353 ReportError(JSONReader::JSON_UNQUOTED_DICTIONARY_KEY, 1); | 353 ReportError(JSONReader::JSON_UNQUOTED_DICTIONARY_KEY, 1); |
354 return nullptr; | 354 return nullptr; |
355 } | 355 } |
356 | 356 |
357 // First consume the key. | 357 // First consume the key. |
(...skipping 11 matching lines...) Expand all Loading... |
369 } | 369 } |
370 | 370 |
371 // The next token is the value. Ownership transfers to |dict|. | 371 // The next token is the value. Ownership transfers to |dict|. |
372 NextChar(); | 372 NextChar(); |
373 std::unique_ptr<Value> value = ParseNextToken(); | 373 std::unique_ptr<Value> value = ParseNextToken(); |
374 if (!value) { | 374 if (!value) { |
375 // ReportError from deeper level. | 375 // ReportError from deeper level. |
376 return nullptr; | 376 return nullptr; |
377 } | 377 } |
378 | 378 |
379 dict_storage.emplace_back(key.DestructiveAsString(), std::move(value)); | 379 dict->SetWithoutPathExpansion(key.AsStringPiece(), std::move(value)); |
380 | 380 |
381 NextChar(); | 381 NextChar(); |
382 token = GetNextToken(); | 382 token = GetNextToken(); |
383 if (token == T_LIST_SEPARATOR) { | 383 if (token == T_LIST_SEPARATOR) { |
384 NextChar(); | 384 NextChar(); |
385 token = GetNextToken(); | 385 token = GetNextToken(); |
386 if (token == T_OBJECT_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) { | 386 if (token == T_OBJECT_END && !(options_ & JSON_ALLOW_TRAILING_COMMAS)) { |
387 ReportError(JSONReader::JSON_TRAILING_COMMA, 1); | 387 ReportError(JSONReader::JSON_TRAILING_COMMA, 1); |
388 return nullptr; | 388 return nullptr; |
389 } | 389 } |
390 } else if (token != T_OBJECT_END) { | 390 } else if (token != T_OBJECT_END) { |
391 ReportError(JSONReader::JSON_SYNTAX_ERROR, 0); | 391 ReportError(JSONReader::JSON_SYNTAX_ERROR, 0); |
392 return nullptr; | 392 return nullptr; |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 return MakeUnique<Value>( | 396 return std::move(dict); |
397 Value::DictStorage(std::move(dict_storage), KEEP_LAST_OF_DUPES)); | |
398 } | 397 } |
399 | 398 |
400 std::unique_ptr<Value> JSONParser::ConsumeList() { | 399 std::unique_ptr<Value> JSONParser::ConsumeList() { |
401 if (*pos_ != '[') { | 400 if (*pos_ != '[') { |
402 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); | 401 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); |
403 return nullptr; | 402 return nullptr; |
404 } | 403 } |
405 | 404 |
406 StackMarker depth_check(&stack_depth_); | 405 StackMarker depth_check(&stack_depth_); |
407 if (depth_check.IsTooDeep()) { | 406 if (depth_check.IsTooDeep()) { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 const std::string& description) { | 829 const std::string& description) { |
831 if (line || column) { | 830 if (line || column) { |
832 return StringPrintf("Line: %i, column: %i, %s", | 831 return StringPrintf("Line: %i, column: %i, %s", |
833 line, column, description.c_str()); | 832 line, column, description.c_str()); |
834 } | 833 } |
835 return description; | 834 return description; |
836 } | 835 } |
837 | 836 |
838 } // namespace internal | 837 } // namespace internal |
839 } // namespace base | 838 } // namespace base |
OLD | NEW |