Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: base/json/json_parser.cc

Issue 1129083003: More base::Values-related bare pointer -> scoped_ptr conversions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/json/json_writer_unittest.cc » ('j') | base/json/json_writer_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | base/json/json_writer_unittest.cc » ('j') | base/json/json_writer_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698