diff options
Diffstat (limited to 'chromium/base/json/json_parser.h')
-rw-r--r-- | chromium/base/json/json_parser.h | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/chromium/base/json/json_parser.h b/chromium/base/json/json_parser.h index 523062e6812..1481a8d2ba7 100644 --- a/chromium/base/json/json_parser.h +++ b/chromium/base/json/json_parser.h @@ -15,10 +15,10 @@ #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/json/json_common.h" -#include "base/json/json_reader.h" #include "base/macros.h" #include "base/optional.h" #include "base/strings/string_piece.h" +#include "base/values.h" namespace base { @@ -44,7 +44,35 @@ class JSONParserTest; // of the next token. class BASE_EXPORT JSONParser { public: - JSONParser(int options, size_t max_depth = kAbsoluteMaxDepth); + // Error codes during parsing. + enum JsonParseError { + JSON_NO_ERROR = base::ValueDeserializer::kErrorCodeNoError, + JSON_SYNTAX_ERROR = base::ValueDeserializer::kErrorCodeInvalidFormat, + JSON_INVALID_ESCAPE, + JSON_UNEXPECTED_TOKEN, + JSON_TRAILING_COMMA, + JSON_TOO_MUCH_NESTING, + JSON_UNEXPECTED_DATA_AFTER_ROOT, + JSON_UNSUPPORTED_ENCODING, + JSON_UNQUOTED_DICTIONARY_KEY, + JSON_TOO_LARGE, + JSON_UNREPRESENTABLE_NUMBER, + JSON_PARSE_ERROR_COUNT + }; + + // String versions of parse error codes. + static const char kSyntaxError[]; + static const char kInvalidEscape[]; + static const char kUnexpectedToken[]; + static const char kTrailingComma[]; + static const char kTooMuchNesting[]; + static const char kUnexpectedDataAfterRoot[]; + static const char kUnsupportedEncoding[]; + static const char kUnquotedDictionaryKey[]; + static const char kInputTooLarge[]; + static const char kUnrepresentableNumber[]; + + explicit JSONParser(int options, size_t max_depth = kAbsoluteMaxDepth); ~JSONParser(); // Parses the input string according to the set options and returns the @@ -54,7 +82,7 @@ class BASE_EXPORT JSONParser { Optional<Value> Parse(StringPiece input); // Returns the error code. - JSONReader::JsonParseError error_code() const; + JsonParseError error_code() const; // Returns the human-friendly error message. std::string GetErrorMessage() const; @@ -205,7 +233,7 @@ class BASE_EXPORT JSONParser { // Sets the error information to |code| at the current column, based on // |index_| and |index_last_line_|, with an optional positive/negative // adjustment by |column_adjust|. - void ReportError(JSONReader::JsonParseError code, int column_adjust); + void ReportError(JsonParseError code, int column_adjust); // Given the line and column number of an error, formats one of the error // message contants from json_reader.h for human display. @@ -234,7 +262,7 @@ class BASE_EXPORT JSONParser { int index_last_line_; // Error information. - JSONReader::JsonParseError error_code_; + JsonParseError error_code_; int error_line_; int error_column_; |