| 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 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 return nullptr; | 729 return nullptr; |
| 730 } | 730 } |
| 731 | 731 |
| 732 pos_ = exit_pos; | 732 pos_ = exit_pos; |
| 733 index_ = exit_index; | 733 index_ = exit_index; |
| 734 | 734 |
| 735 StringPiece num_string(num_start, end_index - start_index); | 735 StringPiece num_string(num_start, end_index - start_index); |
| 736 | 736 |
| 737 int num_int; | 737 int num_int; |
| 738 if (StringToInt(num_string, &num_int)) | 738 if (StringToInt(num_string, &num_int)) |
| 739 return base::MakeUnique<FundamentalValue>(num_int); | 739 return base::MakeUnique<Value>(num_int); |
| 740 | 740 |
| 741 double num_double; | 741 double num_double; |
| 742 if (StringToDouble(num_string.as_string(), &num_double) && | 742 if (StringToDouble(num_string.as_string(), &num_double) && |
| 743 std::isfinite(num_double)) { | 743 std::isfinite(num_double)) { |
| 744 return base::MakeUnique<FundamentalValue>(num_double); | 744 return base::MakeUnique<Value>(num_double); |
| 745 } | 745 } |
| 746 | 746 |
| 747 return nullptr; | 747 return nullptr; |
| 748 } | 748 } |
| 749 | 749 |
| 750 bool JSONParser::ReadInt(bool allow_leading_zeros) { | 750 bool JSONParser::ReadInt(bool allow_leading_zeros) { |
| 751 size_t len = 0; | 751 size_t len = 0; |
| 752 char first = 0; | 752 char first = 0; |
| 753 | 753 |
| 754 while (CanConsume(1)) { | 754 while (CanConsume(1)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 775 switch (*pos_) { | 775 switch (*pos_) { |
| 776 case 't': { | 776 case 't': { |
| 777 const char kTrueLiteral[] = "true"; | 777 const char kTrueLiteral[] = "true"; |
| 778 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); | 778 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); |
| 779 if (!CanConsume(kTrueLen - 1) || | 779 if (!CanConsume(kTrueLen - 1) || |
| 780 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { | 780 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { |
| 781 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 781 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
| 782 return nullptr; | 782 return nullptr; |
| 783 } | 783 } |
| 784 NextNChars(kTrueLen - 1); | 784 NextNChars(kTrueLen - 1); |
| 785 return base::MakeUnique<FundamentalValue>(true); | 785 return base::MakeUnique<Value>(true); |
| 786 } | 786 } |
| 787 case 'f': { | 787 case 'f': { |
| 788 const char kFalseLiteral[] = "false"; | 788 const char kFalseLiteral[] = "false"; |
| 789 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); | 789 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); |
| 790 if (!CanConsume(kFalseLen - 1) || | 790 if (!CanConsume(kFalseLen - 1) || |
| 791 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { | 791 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { |
| 792 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 792 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
| 793 return nullptr; | 793 return nullptr; |
| 794 } | 794 } |
| 795 NextNChars(kFalseLen - 1); | 795 NextNChars(kFalseLen - 1); |
| 796 return base::MakeUnique<FundamentalValue>(false); | 796 return base::MakeUnique<Value>(false); |
| 797 } | 797 } |
| 798 case 'n': { | 798 case 'n': { |
| 799 const char kNullLiteral[] = "null"; | 799 const char kNullLiteral[] = "null"; |
| 800 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); | 800 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); |
| 801 if (!CanConsume(kNullLen - 1) || | 801 if (!CanConsume(kNullLen - 1) || |
| 802 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { | 802 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { |
| 803 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 803 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
| 804 return nullptr; | 804 return nullptr; |
| 805 } | 805 } |
| 806 NextNChars(kNullLen - 1); | 806 NextNChars(kNullLen - 1); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 829 const std::string& description) { | 829 const std::string& description) { |
| 830 if (line || column) { | 830 if (line || column) { |
| 831 return StringPrintf("Line: %i, column: %i, %s", | 831 return StringPrintf("Line: %i, column: %i, %s", |
| 832 line, column, description.c_str()); | 832 line, column, description.c_str()); |
| 833 } | 833 } |
| 834 return description; | 834 return description; |
| 835 } | 835 } |
| 836 | 836 |
| 837 } // namespace internal | 837 } // namespace internal |
| 838 } // namespace base | 838 } // namespace base |
| OLD | NEW |