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

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

Issue 12026035: Recognize "\r\n" line endings in base::JSONParser to report correct line numbers in errors (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 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 | « AUTHORS ('k') | base/json/json_parser_unittest.cc » ('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) 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/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return T_INVALID_TOKEN; 397 return T_INVALID_TOKEN;
398 } 398 }
399 } 399 }
400 400
401 void JSONParser::EatWhitespaceAndComments() { 401 void JSONParser::EatWhitespaceAndComments() {
402 while (pos_ < end_pos_) { 402 while (pos_ < end_pos_) {
403 switch (*pos_) { 403 switch (*pos_) {
404 case '\r': 404 case '\r':
405 case '\n': 405 case '\n':
406 index_last_line_ = index_; 406 index_last_line_ = index_;
407 ++line_number_; 407 // Don't increment line_number_ twice for "\r\n".
408 if (!(*pos_ == '\n' && pos_ > start_pos_ && *(pos_ - 1) == '\r'))
409 ++line_number_;
408 // Fall through. 410 // Fall through.
409 case ' ': 411 case ' ':
410 case '\t': 412 case '\t':
411 NextChar(); 413 NextChar();
412 break; 414 break;
413 case '/': 415 case '/':
414 if (!EatComment()) 416 if (!EatComment())
415 return; 417 return;
416 break; 418 break;
417 default: 419 default:
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 const std::string& description) { 955 const std::string& description) {
954 if (line || column) { 956 if (line || column) {
955 return StringPrintf("Line: %i, column: %i, %s", 957 return StringPrintf("Line: %i, column: %i, %s",
956 line, column, description.c_str()); 958 line, column, description.c_str());
957 } 959 }
958 return description; 960 return description;
959 } 961 }
960 962
961 } // namespace internal 963 } // namespace internal
962 } // namespace base 964 } // namespace base
OLDNEW
« no previous file with comments | « AUTHORS ('k') | base/json/json_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698