Chromium Code Reviews| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 892 |
| 893 if (len == 0) | 893 if (len == 0) |
| 894 return false; | 894 return false; |
| 895 | 895 |
| 896 if (!allow_leading_zeros && len > 1 && first == '0') | 896 if (!allow_leading_zeros && len > 1 && first == '0') |
| 897 return false; | 897 return false; |
| 898 | 898 |
| 899 return true; | 899 return true; |
| 900 } | 900 } |
| 901 | 901 |
| 902 Value* JSONParser::ConsumeLiteral() { | 902 Value* JSONParser::ConsumeLiteral() { |
|
danakj
2015/05/08 18:07:25
TODO to make this return a scoped_ptr?
Evan Stade
2015/05/08 18:32:09
I don't think that's all that helpful. If there we
| |
| 903 switch (*pos_) { | 903 switch (*pos_) { |
| 904 case 't': { | 904 case 't': { |
| 905 const char kTrueLiteral[] = "true"; | 905 const char kTrueLiteral[] = "true"; |
| 906 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); | 906 const int kTrueLen = static_cast<int>(strlen(kTrueLiteral)); |
| 907 if (!CanConsume(kTrueLen - 1) || | 907 if (!CanConsume(kTrueLen - 1) || |
| 908 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { | 908 !StringsAreEqual(pos_, kTrueLiteral, kTrueLen)) { |
| 909 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 909 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
| 910 return NULL; | 910 return NULL; |
| 911 } | 911 } |
| 912 NextNChars(kTrueLen - 1); | 912 NextNChars(kTrueLen - 1); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 925 } | 925 } |
| 926 case 'n': { | 926 case 'n': { |
| 927 const char kNullLiteral[] = "null"; | 927 const char kNullLiteral[] = "null"; |
| 928 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); | 928 const int kNullLen = static_cast<int>(strlen(kNullLiteral)); |
| 929 if (!CanConsume(kNullLen - 1) || | 929 if (!CanConsume(kNullLen - 1) || |
| 930 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { | 930 !StringsAreEqual(pos_, kNullLiteral, kNullLen)) { |
| 931 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 931 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
| 932 return NULL; | 932 return NULL; |
| 933 } | 933 } |
| 934 NextNChars(kNullLen - 1); | 934 NextNChars(kNullLen - 1); |
| 935 return Value::CreateNullValue(); | 935 return Value::CreateNullValue().release(); |
| 936 } | 936 } |
| 937 default: | 937 default: |
| 938 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); | 938 ReportError(JSONReader::JSON_UNEXPECTED_TOKEN, 1); |
| 939 return NULL; | 939 return NULL; |
| 940 } | 940 } |
| 941 } | 941 } |
| 942 | 942 |
| 943 // static | 943 // static |
| 944 bool JSONParser::StringsAreEqual(const char* one, const char* two, size_t len) { | 944 bool JSONParser::StringsAreEqual(const char* one, const char* two, size_t len) { |
| 945 return strncmp(one, two, len) == 0; | 945 return strncmp(one, two, len) == 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 957 const std::string& description) { | 957 const std::string& description) { |
| 958 if (line || column) { | 958 if (line || column) { |
| 959 return StringPrintf("Line: %i, column: %i, %s", | 959 return StringPrintf("Line: %i, column: %i, %s", |
| 960 line, column, description.c_str()); | 960 line, column, description.c_str()); |
| 961 } | 961 } |
| 962 return description; | 962 return description; |
| 963 } | 963 } |
| 964 | 964 |
| 965 } // namespace internal | 965 } // namespace internal |
| 966 } // namespace base | 966 } // namespace base |
| OLD | NEW |