Add parse error codes and API for converting error code to text.

Parse errors is represented as enum type `ParseErrorCode`.
Error texts are optional for user.
Added  `GetParseError_En()` in `error/en.h`, user can localize this file
into other files. User may dynamically change the locale in runtime.
This commit is contained in:
Milo Yip
2014-06-27 01:53:56 +08:00
parent 813eaf4e03
commit 3693d61f5a
7 changed files with 135 additions and 40 deletions

View File

@@ -5,6 +5,7 @@
#include "rapidjson/prettywriter.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/error/en.h"
using namespace rapidjson;
@@ -21,7 +22,7 @@ int main(int, char*[]) {
// JSON reader parse from the input stream and let writer generate the output.
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), reader.GetParseError());
fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), GetParseError_En(reader.GetParseErrorCode()));
return 1;
}