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

Side by Side Diff: base/json_reader.cc

Issue 17047: Update some comments/nits following r7486. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/json_reader.h ('k') | base/values.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_reader.h" 5 #include "base/json_reader.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/string_util.h" 9 #include "base/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 // The conversion from UTF8 to wstring removes null bytes for us 131 // The conversion from UTF8 to wstring removes null bytes for us
132 // (a good thing). 132 // (a good thing).
133 std::wstring json_wide(UTF8ToWide(json)); 133 std::wstring json_wide(UTF8ToWide(json));
134 start_pos_ = json_wide.c_str(); 134 start_pos_ = json_wide.c_str();
135 135
136 // When the input JSON string starts with a UTF-8 Byte-Order-Mark 136 // When the input JSON string starts with a UTF-8 Byte-Order-Mark
137 // (0xEF, 0xBB, 0xBF), the UTF8ToWide() function converts it to a Unicode 137 // (0xEF, 0xBB, 0xBF), the UTF8ToWide() function converts it to a Unicode
138 // BOM (U+FEFF). To avoid the JSONReader::BuildValue() function from 138 // BOM (U+FEFF). To avoid the JSONReader::BuildValue() function from
139 // mis-treating a Unicode BOM as an invalid character and returning false, 139 // mis-treating a Unicode BOM as an invalid character and returning NULL,
140 // skip a converted Unicode BOM if it exists. 140 // skip a converted Unicode BOM if it exists.
141 if (!json_wide.empty() && start_pos_[0] == 0xFEFF) { 141 if (!json_wide.empty() && start_pos_[0] == 0xFEFF) {
142 ++start_pos_; 142 ++start_pos_;
143 } 143 }
144 144
145 json_pos_ = start_pos_; 145 json_pos_ = start_pos_;
146 allow_trailing_comma_ = allow_trailing_comma; 146 allow_trailing_comma_ = allow_trailing_comma;
147 stack_depth_ = 0; 147 stack_depth_ = 0;
148 error_message_.clear(); 148 error_message_.clear();
149 149
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 break; 210 break;
211 211
212 case Token::ARRAY_BEGIN: 212 case Token::ARRAY_BEGIN:
213 { 213 {
214 json_pos_ += token.length; 214 json_pos_ += token.length;
215 token = ParseToken(); 215 token = ParseToken();
216 216
217 node.reset(new ListValue()); 217 node.reset(new ListValue());
218 while (token.type != Token::ARRAY_END) { 218 while (token.type != Token::ARRAY_END) {
219 Value* array_node = BuildValue(false); 219 Value* array_node = BuildValue(false);
220 if (!array_node) { 220 if (!array_node)
221 return NULL; 221 return NULL;
222 }
223 static_cast<ListValue*>(node.get())->Append(array_node); 222 static_cast<ListValue*>(node.get())->Append(array_node);
224 223
225 // After a list value, we expect a comma or the end of the list. 224 // After a list value, we expect a comma or the end of the list.
226 token = ParseToken(); 225 token = ParseToken();
227 if (token.type == Token::LIST_SEPARATOR) { 226 if (token.type == Token::LIST_SEPARATOR) {
228 json_pos_ += token.length; 227 json_pos_ += token.length;
229 token = ParseToken(); 228 token = ParseToken();
230 // Trailing commas are invalid according to the JSON RFC, but some 229 // Trailing commas are invalid according to the JSON RFC, but some
231 // consumers need the parsing leniency, so handle accordingly. 230 // consumers need the parsing leniency, so handle accordingly.
232 if (token.type == Token::ARRAY_END) { 231 if (token.type == Token::ARRAY_END) {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (*pos == '\n') { 630 if (*pos == '\n') {
632 ++line_number; 631 ++line_number;
633 column_number = 1; 632 column_number = 1;
634 } else { 633 } else {
635 ++column_number; 634 ++column_number;
636 } 635 }
637 } 636 }
638 637
639 error_message_ = FormatErrorMessage(line_number, column_number, description); 638 error_message_ = FormatErrorMessage(line_number, column_number, description);
640 } 639 }
OLDNEW
« no previous file with comments | « base/json_reader.h ('k') | base/values.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698