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 "base/float_util.h" | 7 #include "base/float_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 | 894 |
895 if (!allow_leading_zeros && len > 1 && first == '0') | 895 if (!allow_leading_zeros && len > 1 && first == '0') |
896 return false; | 896 return false; |
897 | 897 |
898 return true; | 898 return true; |
899 } | 899 } |
900 | 900 |
901 Value* JSONParser::ConsumeLiteral() { | 901 Value* JSONParser::ConsumeLiteral() { |
902 switch (*pos_) { | 902 switch (*pos_) { |
903 case 't': { | 903 case 't': { |
904 const char* kTrueLiteral = "true"; | 904 const char kTrueLiteral[] = "true"; |
905 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); | 905 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); |
906 if (!CanConsume(kTrueLen - 1) || | 906 if (!CanConsume(kTrueLen - 1) || |
907 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { | 907 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { |
908 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 908 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
909 return NULL; | 909 return NULL; |
910 } | 910 } |
911 NextNChars(kTrueLen - 1); | 911 NextNChars(kTrueLen - 1); |
912 return new FundamentalValue(true); | 912 return new FundamentalValue(true); |
913 } | 913 } |
914 case 'f': { | 914 case 'f': { |
915 const char* kFalseLiteral = "false"; | 915 const char kFalseLiteral[] = "false"; |
916 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); | 916 const int kFalseLen = static_cast<int>(strlen(kFalseLiteral)); |
917 if (!CanConsume(kFalseLen - 1) || | 917 if (!CanConsume(kFalseLen - 1) || |
918 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { | 918 !StringsAreEqual(pos_, kFalseLiteral, kFalseLen)) { |
919 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 919 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
920 return NULL; | 920 return NULL; |
921 } | 921 } |
922 NextNChars(kFalseLen - 1); | 922 NextNChars(kFalseLen - 1); |
923 return new FundamentalValue(false); | 923 return new FundamentalValue(false); |
924 } | 924 } |
925 case 'n': { | 925 case 'n': { |
926 const char* kNullLiteral = "null"; | 926 const char kNullLiteral[] = "null"; |
927 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); | 927 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); |
928 if (!CanConsume(kNullLen - 1) || | 928 if (!CanConsume(kNullLen - 1) || |
929 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { | 929 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { |
930 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 930 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
931 return NULL; | 931 return NULL; |
932 } | 932 } |
933 NextNChars(kNullLen - 1); | 933 NextNChars(kNullLen - 1); |
934 return Value::CreateNullValue(); | 934 return Value::CreateNullValue(); |
935 } | 935 } |
936 default: | 936 default: |
(...skipping 19 matching lines...) Expand all Loading... |
956 const std::string& description) { | 956 const std::string& description) { |
957 if (line || column) { | 957 if (line || column) { |
958 return StringPrintf("Line: %i, column: %i, %s", | 958 return StringPrintf("Line: %i, column: %i, %s", |
959 line, column, description.c_str()); | 959 line, column, description.c_str()); |
960 } | 960 } |
961 return description; | 961 return description; |
962 } | 962 } |
963 | 963 |
964 } // namespace internal | 964 } // namespace internal |
965 } // namespace base | 965 } // namespace base |
OLD | NEW |