Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: base/json/json_reader.h

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/json/json_parser_unittest.cc ('k') | base/json/json_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Constructs a reader with the default options, JSON_PARSE_RFC. 87 // Constructs a reader with the default options, JSON_PARSE_RFC.
88 JSONReader(); 88 JSONReader();
89 89
90 // Constructs a reader with custom options. 90 // Constructs a reader with custom options.
91 explicit JSONReader(int options); 91 explicit JSONReader(int options);
92 92
93 ~JSONReader(); 93 ~JSONReader();
94 94
95 // Reads and parses |json|, returning a Value. The caller owns the returned 95 // Reads and parses |json|, returning a Value. The caller owns the returned
96 // instance. If |json| is not a properly formed JSON string, returns NULL. 96 // instance. If |json| is not a properly formed JSON string, returns NULL.
97 static Value* Read(const StringPiece& json); 97 static scoped_ptr<Value> Read(const StringPiece& json);
98 // TODO(estade): remove this bare pointer version.
99 static Value* DeprecatedRead(const StringPiece& json);
98 100
99 // Reads and parses |json|, returning a Value owned by the caller. The 101 // Reads and parses |json|, returning a Value owned by the caller. The
100 // parser respects the given |options|. If the input is not properly formed, 102 // parser respects the given |options|. If the input is not properly formed,
101 // returns NULL. 103 // returns NULL.
102 static Value* Read(const StringPiece& json, int options); 104 static scoped_ptr<Value> Read(const StringPiece& json, int options);
105 // TODO(estade): remove this bare pointer version.
106 static Value* DeprecatedRead(const StringPiece& json, int options);
103 107
104 // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out| 108 // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out|
105 // are optional. If specified and NULL is returned, they will be populated 109 // are optional. If specified and NULL is returned, they will be populated
106 // an error code and a formatted error message (including error location if 110 // an error code and a formatted error message (including error location if
107 // appropriate). Otherwise, they will be unmodified. 111 // appropriate). Otherwise, they will be unmodified.
108 static Value* ReadAndReturnError(const StringPiece& json, 112 static scoped_ptr<Value> ReadAndReturnError(const StringPiece& json,
109 int options, // JSONParserOptions 113 int options, // JSONParserOptions
110 int* error_code_out, 114 int* error_code_out,
111 std::string* error_msg_out); 115 std::string* error_msg_out);
116 // TODO(estade): remove this bare pointer version.
117 static Value* DeprecatedReadAndReturnError(const StringPiece& json,
118 int options, // JSONParserOptions
119 int* error_code_out,
120 std::string* error_msg_out);
112 121
113 // Converts a JSON parse error code into a human readable message. 122 // Converts a JSON parse error code into a human readable message.
114 // Returns an empty string if error_code is JSON_NO_ERROR. 123 // Returns an empty string if error_code is JSON_NO_ERROR.
115 static std::string ErrorCodeToString(JsonParseError error_code); 124 static std::string ErrorCodeToString(JsonParseError error_code);
116 125
117 // Parses an input string into a Value that is owned by the caller. 126 // Parses an input string into a Value that is owned by the caller.
118 Value* ReadToValue(const std::string& json); 127 scoped_ptr<Value> ReadToValue(const std::string& json);
119 128
120 // Returns the error code if the last call to ReadToValue() failed. 129 // Returns the error code if the last call to ReadToValue() failed.
121 // Returns JSON_NO_ERROR otherwise. 130 // Returns JSON_NO_ERROR otherwise.
122 JsonParseError error_code() const; 131 JsonParseError error_code() const;
123 132
124 // Converts error_code_ to a human-readable string, including line and column 133 // Converts error_code_ to a human-readable string, including line and column
125 // numbers if appropriate. 134 // numbers if appropriate.
126 std::string GetErrorMessage() const; 135 std::string GetErrorMessage() const;
127 136
128 private: 137 private:
129 scoped_ptr<internal::JSONParser> parser_; 138 scoped_ptr<internal::JSONParser> parser_;
130 }; 139 };
131 140
132 } // namespace base 141 } // namespace base
133 142
134 #endif // BASE_JSON_JSON_READER_H_ 143 #endif // BASE_JSON_JSON_READER_H_
OLDNEW
« no previous file with comments | « base/json/json_parser_unittest.cc ('k') | base/json/json_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698