| 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 |
| 11 // decimal numbers within a double. | 11 // decimal numbers within a double. |
| 12 // - Assumes input is encoded as UTF8. The spec says we should allow UTF-16 | 12 // - Assumes input is encoded as UTF8. The spec says we should allow UTF-16 |
| 13 // (BE or LE) and UTF-32 (BE or LE) as well. | 13 // (BE or LE) and UTF-32 (BE or LE) as well. |
| 14 // - We limit nesting to 100 levels to prevent stack overflow (this is allowed | 14 // - We limit nesting to 100 levels to prevent stack overflow (this is allowed |
| 15 // by the RFC). | 15 // by the RFC). |
| 16 // - A Unicode FAQ ("http://unicode.org/faq/utf_bom.html") writes a data | 16 // - A Unicode FAQ ("http://unicode.org/faq/utf_bom.html") writes a data |
| 17 // stream may start with a Unicode Byte-Order-Mark (U+FEFF), i.e. the input | 17 // stream may start with a Unicode Byte-Order-Mark (U+FEFF), i.e. the input |
| 18 // UTF-8 string for the JSONReader::JsonToValue() function may start with a | 18 // UTF-8 string for the JSONReader::JsonToValue() function may start with a |
| 19 // UTF-8 BOM (0xEF, 0xBB, 0xBF). | 19 // UTF-8 BOM (0xEF, 0xBB, 0xBF). |
| 20 // To avoid the function from mis-treating a UTF-8 BOM as an invalid | 20 // To avoid the function from mis-treating a UTF-8 BOM as an invalid |
| 21 // character, the function skips a Unicode BOM at the beginning of the | 21 // character, the function skips a Unicode BOM at the beginning of the |
| 22 // Unicode string (converted from the input UTF-8 string) before parsing it. | 22 // Unicode string (converted from the input UTF-8 string) before parsing it. |
| 23 // | 23 // |
| 24 // TODO(tc): Add a parsing option to to relax object keys being wrapped in | 24 // TODO(tc): Add a parsing option to to relax object keys being wrapped in |
| 25 // double quotes | 25 // double quotes |
| 26 // TODO(tc): Add an option to disable comment stripping | 26 // TODO(tc): Add an option to disable comment stripping |
| 27 | 27 |
| 28 #ifndef BASE_JSON_JSON_READER_H_ | 28 #ifndef BASE_JSON_JSON_READER_H_ |
| 29 #define BASE_JSON_JSON_READER_H_ | 29 #define BASE_JSON_JSON_READER_H_ |
| 30 #pragma once | |
| 31 | 30 |
| 32 #include <string> | 31 #include <string> |
| 33 | 32 |
| 34 #include "base/base_export.h" | 33 #include "base/base_export.h" |
| 35 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
| 36 #include "base/string_piece.h" | 35 #include "base/string_piece.h" |
| 37 #include "base/memory/scoped_ptr.h" | 36 #include "base/memory/scoped_ptr.h" |
| 38 | 37 |
| 39 namespace base { | 38 namespace base { |
| 40 class Value; | 39 class Value; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // numbers if appropriate. | 126 // numbers if appropriate. |
| 128 std::string GetErrorMessage() const; | 127 std::string GetErrorMessage() const; |
| 129 | 128 |
| 130 private: | 129 private: |
| 131 scoped_ptr<internal::JSONParser> parser_; | 130 scoped_ptr<internal::JSONParser> parser_; |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 } // namespace base | 133 } // namespace base |
| 135 | 134 |
| 136 #endif // BASE_JSON_JSON_READER_H_ | 135 #endif // BASE_JSON_JSON_READER_H_ |
| OLD | NEW |