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

Unified Diff: base/json/json_reader.h

Issue 9960077: Modify the base::JSONReader interface to take a set of options rather than a boolean flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/json/json_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_reader.h
diff --git a/base/json/json_reader.h b/base/json/json_reader.h
index b1edfb07edd4c2bd7c736cb150e24e77703deab0..34151df73c947523a0bd638f45d15047d0356748 100644
--- a/base/json/json_reader.h
+++ b/base/json/json_reader.h
@@ -50,6 +50,14 @@ namespace base {
class Value;
+enum JSONParserOptions {
+ // Parses the input strictly according to RFC 4627, except for where noted
+ // above.
+ JSON_PARSE_RFC = 0,
+ // Allows commas to exist after the last element in structures.
Mark Mentovai 2012/04/10 22:08:28 Blank line before.
+ JSON_ALLOW_TRAILING_COMMAS = 1 << 0,
+};
+
class BASE_EXPORT JSONReader {
public:
// A struct to hold a JS token.
@@ -119,16 +127,19 @@ class BASE_EXPORT JSONReader {
// Reads and parses |json|, returning a Value. The caller owns the returned
// instance. If |json| is not a properly formed JSON string, returns NULL.
- // If |allow_trailing_comma| is true, we will ignore trailing commas in
- // objects and arrays even though this goes against the RFC.
- static Value* Read(const std::string& json, bool allow_trailing_comma);
+ static Value* Read(const std::string& json);
+
+ // Reads and parses |json|, returning a Value owned by the caller. The
+ // parser respects the given |options|. If the input is not properly formed,
+ // returns NULL.
+ static Value* Read(const std::string& json, int options);
// Reads and parses |json| like Read(). |error_code_out| and |error_msg_out|
// are optional. If specified and NULL is returned, they will be populated
// an error code and a formatted error message (including error location if
// appropriate). Otherwise, they will be unmodified.
static Value* ReadAndReturnError(const std::string& json,
- bool allow_trailing_comma,
+ int options, // JSONParserOptions
int* error_code_out,
std::string* error_msg_out);
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/json/json_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698