| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 JSON_PARSE_RFC = 0, | 48 JSON_PARSE_RFC = 0, |
| 49 | 49 |
| 50 // Allows commas to exist after the last element in structures. | 50 // Allows commas to exist after the last element in structures. |
| 51 JSON_ALLOW_TRAILING_COMMAS = 1 << 0, | 51 JSON_ALLOW_TRAILING_COMMAS = 1 << 0, |
| 52 | 52 |
| 53 // The parser can perform optimizations by placing hidden data in the root of | 53 // The parser can perform optimizations by placing hidden data in the root of |
| 54 // the JSON object, which speeds up certain operations on children. However, | 54 // the JSON object, which speeds up certain operations on children. However, |
| 55 // if the child is Remove()d from root, it would result in use-after-free | 55 // if the child is Remove()d from root, it would result in use-after-free |
| 56 // unless it is DeepCopy()ed or this option is used. | 56 // unless it is DeepCopy()ed or this option is used. |
| 57 JSON_DETACHABLE_CHILDREN = 1 << 1, | 57 JSON_DETACHABLE_CHILDREN = 1 << 1, |
| 58 |
| 59 // If set the parser replaces invalid characters with the Unicode replacement |
| 60 // character (U+FFFD). If not set, invalid characters trigger a hard error and |
| 61 // parsing fails. |
| 62 JSON_REPLACE_INVALID_CHARACTERS = 1 << 2, |
| 58 }; | 63 }; |
| 59 | 64 |
| 60 class BASE_EXPORT JSONReader { | 65 class BASE_EXPORT JSONReader { |
| 61 public: | 66 public: |
| 62 // Error codes during parsing. | 67 // Error codes during parsing. |
| 63 enum JsonParseError { | 68 enum JsonParseError { |
| 64 JSON_NO_ERROR = 0, | 69 JSON_NO_ERROR = 0, |
| 65 JSON_INVALID_ESCAPE, | 70 JSON_INVALID_ESCAPE, |
| 66 JSON_SYNTAX_ERROR, | 71 JSON_SYNTAX_ERROR, |
| 67 JSON_UNEXPECTED_TOKEN, | 72 JSON_UNEXPECTED_TOKEN, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // numbers if appropriate. | 132 // numbers if appropriate. |
| 128 std::string GetErrorMessage() const; | 133 std::string GetErrorMessage() const; |
| 129 | 134 |
| 130 private: | 135 private: |
| 131 std::unique_ptr<internal::JSONParser> parser_; | 136 std::unique_ptr<internal::JSONParser> parser_; |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 } // namespace base | 139 } // namespace base |
| 135 | 140 |
| 136 #endif // BASE_JSON_JSON_READER_H_ | 141 #endif // BASE_JSON_JSON_READER_H_ |
| OLD | NEW |