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 // 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 // returns NULL. | 100 // returns NULL. |
| 101 static scoped_ptr<Value> Read(const StringPiece& json, int options); | 101 static scoped_ptr<Value> Read(const StringPiece& json, int options); |
| 102 | 102 |
| 103 // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out| | 103 // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out| |
| 104 // are optional. If specified and NULL is returned, they will be populated | 104 // are optional. If specified and NULL is returned, they will be populated |
| 105 // an error code and a formatted error message (including error location if | 105 // an error code and a formatted error message (including error location if |
| 106 // appropriate). Otherwise, they will be unmodified. | 106 // appropriate). Otherwise, they will be unmodified. |
| 107 static scoped_ptr<Value> ReadAndReturnError(const StringPiece& json, | 107 static scoped_ptr<Value> ReadAndReturnError(const StringPiece& json, |
| 108 int options, // JSONParserOptions | 108 int options, // JSONParserOptions |
| 109 int* error_code_out, | 109 int* error_code_out, |
| 110 std::string* error_msg_out); | 110 std::string* error_msg_out, |
| 111 int* error_line_out = nullptr, | |
| 112 int* error_column_out = nullptr); | |
|
Nico
2016/01/13 20:50:39
That'd also help here...
| |
| 111 | 113 |
| 112 // Converts a JSON parse error code into a human readable message. | 114 // Converts a JSON parse error code into a human readable message. |
| 113 // Returns an empty string if error_code is JSON_NO_ERROR. | 115 // Returns an empty string if error_code is JSON_NO_ERROR. |
| 114 static std::string ErrorCodeToString(JsonParseError error_code); | 116 static std::string ErrorCodeToString(JsonParseError error_code); |
| 115 | 117 |
| 116 // Parses an input string into a Value that is owned by the caller. | 118 // Parses an input string into a Value that is owned by the caller. |
| 117 scoped_ptr<Value> ReadToValue(const std::string& json); | 119 scoped_ptr<Value> ReadToValue(const std::string& json); |
| 118 | 120 |
| 119 // Returns the error code if the last call to ReadToValue() failed. | 121 // Returns the error code if the last call to ReadToValue() failed. |
| 120 // Returns JSON_NO_ERROR otherwise. | 122 // Returns JSON_NO_ERROR otherwise. |
| 121 JsonParseError error_code() const; | 123 JsonParseError error_code() const; |
| 122 | 124 |
| 123 // Converts error_code_ to a human-readable string, including line and column | 125 // Converts error_code_ to a human-readable string, including line and column |
| 124 // numbers if appropriate. | 126 // numbers if appropriate. |
| 125 std::string GetErrorMessage() const; | 127 std::string GetErrorMessage() const; |
| 126 | 128 |
| 127 private: | 129 private: |
| 128 scoped_ptr<internal::JSONParser> parser_; | 130 scoped_ptr<internal::JSONParser> parser_; |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 } // namespace base | 133 } // namespace base |
| 132 | 134 |
| 133 #endif // BASE_JSON_JSON_READER_H_ | 135 #endif // BASE_JSON_JSON_READER_H_ |
| OLD | NEW |