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 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 return nullptr; | 894 return nullptr; |
895 } | 895 } |
896 | 896 |
897 pos_ = exit_pos; | 897 pos_ = exit_pos; |
898 index_ = exit_index; | 898 index_ = exit_index; |
899 | 899 |
900 StringPiece num_string(num_start, end_index - start_index); | 900 StringPiece num_string(num_start, end_index - start_index); |
901 | 901 |
902 int num_int; | 902 int num_int; |
903 if (StringToInt(num_string, &num_int)) | 903 if (StringToInt(num_string, &num_int)) |
904 return base::MakeUnique<FundamentalValue>(num_int); | 904 return base::MakeUnique<Value>(num_int); |
905 | 905 |
906 double num_double; | 906 double num_double; |
907 if (StringToDouble(num_string.as_string(), &num_double) && | 907 if (StringToDouble(num_string.as_string(), &num_double) && |
908 std::isfinite(num_double)) { | 908 std::isfinite(num_double)) { |
909 return base::MakeUnique<FundamentalValue>(num_double); | 909 return base::MakeUnique<Value>(num_double); |
910 } | 910 } |
911 | 911 |
912 return nullptr; | 912 return nullptr; |
913 } | 913 } |
914 | 914 |
915 bool JSONParser::ReadInt(bool allow_leading_zeros) { | 915 bool JSONParser::ReadInt(bool allow_leading_zeros) { |
916 char first = *pos_; | 916 char first = *pos_; |
917 int len = 0; | 917 int len = 0; |
918 | 918 |
919 char c = first; | 919 char c = first; |
(...skipping 15 matching lines...) Expand all Loading... |
935 switch (*pos_) { | 935 switch (*pos_) { |
936 case 't': { | 936 case 't': { |
937 const char kTrueLiteral[] = "true"; | 937 const char kTrueLiteral[] = "true"; |
938 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); | 938 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); |
939 if (!CanConsume(kTrueLen - 1) || | 939 if (!CanConsume(kTrueLen - 1) || |
940 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { | 940 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { |
941 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 941 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
942 return nullptr; | 942 return nullptr; |
943 } | 943 } |
944 NextNChars(kTrueLen - 1); | 944 NextNChars(kTrueLen - 1); |
945 return base::MakeUnique<FundamentalValue>(true); | 945 return base::MakeUnique<Value>(true); |
946 } | 946 } |
947 case 'f': { | 947 case 'f': { |
948 const char kFalseLiteral[] = "false"; | 948 const char kFalseLiteral[] = "false"; |
949 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); | 949 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); |
950 if (!CanConsume(kFalseLen - 1) || | 950 if (!CanConsume(kFalseLen - 1) || |
951 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { | 951 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { |
952 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 952 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
953 return nullptr; | 953 return nullptr; |
954 } | 954 } |
955 NextNChars(kFalseLen - 1); | 955 NextNChars(kFalseLen - 1); |
956 return base::MakeUnique<FundamentalValue>(false); | 956 return base::MakeUnique<Value>(false); |
957 } | 957 } |
958 case 'n': { | 958 case 'n': { |
959 const char kNullLiteral[] = "null"; | 959 const char kNullLiteral[] = "null"; |
960 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); | 960 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); |
961 if (!CanConsume(kNullLen - 1) || | 961 if (!CanConsume(kNullLen - 1) || |
962 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { | 962 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { |
963 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 963 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
964 return nullptr; | 964 return nullptr; |
965 } | 965 } |
966 NextNChars(kNullLen - 1); | 966 NextNChars(kNullLen - 1); |
(...skipping 22 matching lines...) Expand all Loading... |
989 const std::string& description) { | 989 const std::string& description) { |
990 if (line || column) { | 990 if (line || column) { |
991 return StringPrintf("Line: %i, column: %i, %s", | 991 return StringPrintf("Line: %i, column: %i, %s", |
992 line, column, description.c_str()); | 992 line, column, description.c_str()); |
993 } | 993 } |
994 return description; | 994 return description; |
995 } | 995 } |
996 | 996 |
997 } // namespace internal | 997 } // namespace internal |
998 } // namespace base | 998 } // namespace base |
OLD | NEW |