| 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_reader.h" | 5 #include "base/json/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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 : start_pos_(NULL), | 86 : start_pos_(NULL), |
| 87 json_pos_(NULL), | 87 json_pos_(NULL), |
| 88 end_pos_(NULL), | 88 end_pos_(NULL), |
| 89 stack_depth_(0), | 89 stack_depth_(0), |
| 90 allow_trailing_comma_(false), | 90 allow_trailing_comma_(false), |
| 91 error_code_(JSON_NO_ERROR), | 91 error_code_(JSON_NO_ERROR), |
| 92 error_line_(0), | 92 error_line_(0), |
| 93 error_col_(0) {} | 93 error_col_(0) {} |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 Value* JSONReader::Read(const std::string& json) { |
| 97 return Read(json, JSON_PARSE_RFC); |
| 98 } |
| 99 |
| 100 // static |
| 96 Value* JSONReader::Read(const std::string& json, | 101 Value* JSONReader::Read(const std::string& json, |
| 97 bool allow_trailing_comma) { | 102 int options) { |
| 98 return ReadAndReturnError(json, allow_trailing_comma, NULL, NULL); | 103 return ReadAndReturnError(json, options, NULL, NULL); |
| 99 } | 104 } |
| 100 | 105 |
| 101 // static | 106 // static |
| 102 Value* JSONReader::ReadAndReturnError(const std::string& json, | 107 Value* JSONReader::ReadAndReturnError(const std::string& json, |
| 103 bool allow_trailing_comma, | 108 int options, |
| 104 int* error_code_out, | 109 int* error_code_out, |
| 105 std::string* error_msg_out) { | 110 std::string* error_msg_out) { |
| 106 JSONReader reader = JSONReader(); | 111 JSONReader reader = JSONReader(); |
| 107 Value* root = reader.JsonToValue(json, true, allow_trailing_comma); | 112 Value* root = reader.JsonToValue(json, false, |
| 113 (options & JSON_ALLOW_TRAILING_COMMAS) != 0); |
| 108 if (root) | 114 if (root) |
| 109 return root; | 115 return root; |
| 110 | 116 |
| 111 if (error_code_out) | 117 if (error_code_out) |
| 112 *error_code_out = reader.error_code(); | 118 *error_code_out = reader.error_code(); |
| 113 if (error_msg_out) | 119 if (error_msg_out) |
| 114 *error_msg_out = reader.GetErrorMessage(); | 120 *error_msg_out = reader.GetErrorMessage(); |
| 115 | 121 |
| 116 return NULL; | 122 return NULL; |
| 117 } | 123 } |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 ++column_number; | 725 ++column_number; |
| 720 } | 726 } |
| 721 } | 727 } |
| 722 | 728 |
| 723 error_line_ = line_number; | 729 error_line_ = line_number; |
| 724 error_col_ = column_number; | 730 error_col_ = column_number; |
| 725 error_code_ = error; | 731 error_code_ = error; |
| 726 } | 732 } |
| 727 | 733 |
| 728 } // namespace base | 734 } // namespace base |
| OLD | NEW |