| 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/json/json_parser.h" | 7 #include "base/json/json_parser.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 scoped_ptr<Value> JSONReader::Read(const StringPiece& json, int options) { | 52 scoped_ptr<Value> JSONReader::Read(const StringPiece& json, int options) { |
| 53 internal::JSONParser parser(options); | 53 internal::JSONParser parser(options); |
| 54 return make_scoped_ptr(parser.Parse(json)); | 54 return make_scoped_ptr(parser.Parse(json)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 scoped_ptr<Value> JSONReader::ReadAndReturnError(const StringPiece& json, | 59 scoped_ptr<Value> JSONReader::ReadAndReturnError(const StringPiece& json, |
| 60 int options, | 60 int options, |
| 61 int* error_code_out, | 61 int* error_code_out, |
| 62 std::string* error_msg_out) { | 62 std::string* error_msg_out, |
| 63 int* error_line_out, |
| 64 int* error_column_out) { |
| 63 internal::JSONParser parser(options); | 65 internal::JSONParser parser(options); |
| 64 scoped_ptr<Value> root(parser.Parse(json)); | 66 scoped_ptr<Value> root(parser.Parse(json)); |
| 65 if (!root) { | 67 if (!root) { |
| 66 if (error_code_out) | 68 if (error_code_out) |
| 67 *error_code_out = parser.error_code(); | 69 *error_code_out = parser.error_code(); |
| 68 if (error_msg_out) | 70 if (error_msg_out) |
| 69 *error_msg_out = parser.GetErrorMessage(); | 71 *error_msg_out = parser.GetErrorMessage(); |
| 72 if (error_line_out) |
| 73 *error_line_out = parser.error_line(); |
| 74 if (error_column_out) |
| 75 *error_column_out = parser.error_column(); |
| 70 } | 76 } |
| 71 | 77 |
| 72 return root; | 78 return root; |
| 73 } | 79 } |
| 74 | 80 |
| 75 // static | 81 // static |
| 76 std::string JSONReader::ErrorCodeToString(JsonParseError error_code) { | 82 std::string JSONReader::ErrorCodeToString(JsonParseError error_code) { |
| 77 switch (error_code) { | 83 switch (error_code) { |
| 78 case JSON_NO_ERROR: | 84 case JSON_NO_ERROR: |
| 79 return std::string(); | 85 return std::string(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 105 | 111 |
| 106 JSONReader::JsonParseError JSONReader::error_code() const { | 112 JSONReader::JsonParseError JSONReader::error_code() const { |
| 107 return parser_->error_code(); | 113 return parser_->error_code(); |
| 108 } | 114 } |
| 109 | 115 |
| 110 std::string JSONReader::GetErrorMessage() const { | 116 std::string JSONReader::GetErrorMessage() const { |
| 111 return parser_->GetErrorMessage(); | 117 return parser_->GetErrorMessage(); |
| 112 } | 118 } |
| 113 | 119 |
| 114 } // namespace base | 120 } // namespace base |
| OLD | NEW |