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 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 181 } | 
| 182 | 182 | 
| 183 private: | 183 private: | 
| 184 int* const depth_; | 184 int* const depth_; | 
| 185 | 185 | 
| 186 DISALLOW_COPY_AND_ASSIGN(StackMarker); | 186 DISALLOW_COPY_AND_ASSIGN(StackMarker); | 
| 187 }; | 187 }; | 
| 188 | 188 | 
| 189 } // namespace | 189 } // namespace | 
| 190 | 190 | 
| 191 const char kUnicodeReplacementString[] = "\xFF\xDF"; | |
| 
 
brettw
2016/11/08 19:21:19
I'm not sure where you got this string. U+FFFD in
 
brettw
2016/11/08 20:26:56
(add x's in there after the backslashes)
 
sky
2016/11/08 23:55:35
Done.
 
 | |
| 192 | |
| 191 JSONParser::JSONParser(int options) | 193 JSONParser::JSONParser(int options) | 
| 192 : options_(options), | 194 : options_(options), | 
| 193 start_pos_(nullptr), | 195 start_pos_(nullptr), | 
| 194 pos_(nullptr), | 196 pos_(nullptr), | 
| 195 end_pos_(nullptr), | 197 end_pos_(nullptr), | 
| 196 index_(0), | 198 index_(0), | 
| 197 stack_depth_(0), | 199 stack_depth_(0), | 
| 198 line_number_(0), | 200 line_number_(0), | 
| 199 index_last_line_(0), | 201 index_last_line_(0), | 
| 200 error_code_(JSONReader::JSON_NO_ERROR), | 202 error_code_(JSONReader::JSON_NO_ERROR), | 
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 // std::string. | 624 // std::string. | 
| 623 StringBuilder string(NextChar()); | 625 StringBuilder string(NextChar()); | 
| 624 | 626 | 
| 625 int length = end_pos_ - start_pos_; | 627 int length = end_pos_ - start_pos_; | 
| 626 int32_t next_char = 0; | 628 int32_t next_char = 0; | 
| 627 | 629 | 
| 628 while (CanConsume(1)) { | 630 while (CanConsume(1)) { | 
| 629 pos_ = start_pos_ + index_; // CBU8_NEXT is postcrement. | 631 pos_ = start_pos_ + index_; // CBU8_NEXT is postcrement. | 
| 630 CBU8_NEXT(start_pos_, index_, length, next_char); | 632 CBU8_NEXT(start_pos_, index_, length, next_char); | 
| 631 if (next_char < 0 || !IsValidCharacter(next_char)) { | 633 if (next_char < 0 || !IsValidCharacter(next_char)) { | 
| 632 ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1); | 634 if ((options_ & JSON_REPLACE_INVALID_CHARACTERS) == 0) { | 
| 633 return false; | 635 ReportError(JSONReader::JSON_UNSUPPORTED_ENCODING, 1); | 
| 636 return false; | |
| 637 } | |
| 638 string.Convert(); | |
| 639 string.AppendString(kUnicodeReplacementString); | |
| 640 continue; | |
| 634 } | 641 } | 
| 635 | 642 | 
| 636 if (next_char == '"') { | 643 if (next_char == '"') { | 
| 637 --index_; // Rewind by one because of CBU8_NEXT. | 644 --index_; // Rewind by one because of CBU8_NEXT. | 
| 638 out->Swap(&string); | 645 out->Swap(&string); | 
| 639 return true; | 646 return true; | 
| 640 } | 647 } | 
| 641 | 648 | 
| 642 // If this character is not an escape sequence... | 649 // If this character is not an escape sequence... | 
| 643 if (next_char != '\\') { | 650 if (next_char != '\\') { | 
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 const std::string& description) { | 986 const std::string& description) { | 
| 980 if (line || column) { | 987 if (line || column) { | 
| 981 return StringPrintf("Line: %i, column: %i, %s", | 988 return StringPrintf("Line: %i, column: %i, %s", | 
| 982 line, column, description.c_str()); | 989 line, column, description.c_str()); | 
| 983 } | 990 } | 
| 984 return description; | 991 return description; | 
| 985 } | 992 } | 
| 986 | 993 | 
| 987 } // namespace internal | 994 } // namespace internal | 
| 988 } // namespace base | 995 } // namespace base | 
| OLD | NEW |