| 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 // A JSON parser. Converts strings of JSON into a Value object (see | 5 // A JSON parser. Converts strings of JSON into a Value object (see |
| 6 // base/values.h). | 6 // base/values.h). |
| 7 // http://www.ietf.org/rfc/rfc4627.txt?number=4627 | 7 // http://www.ietf.org/rfc/rfc4627.txt?number=4627 |
| 8 // | 8 // |
| 9 // Known limitations/deviations from the RFC: | 9 // Known limitations/deviations from the RFC: |
| 10 // - Only knows how to parse ints within the range of a signed 32 bit int and | 10 // - Only knows how to parse ints within the range of a signed 32 bit int and |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 static Value* ReadAndReturnError(const StringPiece& json, | 108 static Value* ReadAndReturnError(const StringPiece& json, |
| 109 int options, // JSONParserOptions | 109 int options, // JSONParserOptions |
| 110 int* error_code_out, | 110 int* error_code_out, |
| 111 std::string* error_msg_out); | 111 std::string* error_msg_out); |
| 112 | 112 |
| 113 // Converts a JSON parse error code into a human readable message. | 113 // Converts a JSON parse error code into a human readable message. |
| 114 // Returns an empty string if error_code is JSON_NO_ERROR. | 114 // Returns an empty string if error_code is JSON_NO_ERROR. |
| 115 static std::string ErrorCodeToString(JsonParseError error_code); | 115 static std::string ErrorCodeToString(JsonParseError error_code); |
| 116 | 116 |
| 117 // Parses an input string into a Value that is owned by the caller. | 117 // Parses an input string into a Value that is owned by the caller. |
| 118 Value* ReadToValue(const std::string& json); | 118 scoped_ptr<Value> ReadToValue(const std::string& json); |
| 119 | 119 |
| 120 // Returns the error code if the last call to ReadToValue() failed. | 120 // Returns the error code if the last call to ReadToValue() failed. |
| 121 // Returns JSON_NO_ERROR otherwise. | 121 // Returns JSON_NO_ERROR otherwise. |
| 122 JsonParseError error_code() const; | 122 JsonParseError error_code() const; |
| 123 | 123 |
| 124 // Converts error_code_ to a human-readable string, including line and column | 124 // Converts error_code_ to a human-readable string, including line and column |
| 125 // numbers if appropriate. | 125 // numbers if appropriate. |
| 126 std::string GetErrorMessage() const; | 126 std::string GetErrorMessage() const; |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 scoped_ptr<internal::JSONParser> parser_; | 129 scoped_ptr<internal::JSONParser> parser_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 } // namespace base | 132 } // namespace base |
| 133 | 133 |
| 134 #endif // BASE_JSON_JSON_READER_H_ | 134 #endif // BASE_JSON_JSON_READER_H_ |
| OLD | NEW |