diff options
author | Milo Yip <miloyip@gmail.com> | 2014-06-26 21:53:56 +0400 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2014-06-26 21:53:56 +0400 |
commit | 3693d61f5a8625cfea75305d4c7b84cd5f189993 (patch) | |
tree | 89c73c907d09b238b62626357ece8cfaab5403d6 /example | |
parent | 813eaf4e031e41da1ba6392dcbaac42e40ec2598 (diff) |
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.
Diffstat (limited to 'example')
-rw-r--r-- | example/condense/condense.cpp | 3 | ||||
-rw-r--r-- | example/pretty/pretty.cpp | 3 | ||||
-rw-r--r-- | example/prettyauto/prettyauto.cpp | 3 |
3 files changed, 6 insertions, 3 deletions
diff --git a/example/condense/condense.cpp b/example/condense/condense.cpp index 8f1da83f..ae6d36ac 100644 --- a/example/condense/condense.cpp +++ b/example/condense/condense.cpp @@ -7,6 +7,7 @@ #include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
+#include "rapidjson/error/en.h"
using namespace rapidjson;
@@ -23,7 +24,7 @@ int main(int, char*[]) { // JSON reader parse from the input stream and let writer generate the output.
if (!reader.Parse<0>(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;
}
diff --git a/example/pretty/pretty.cpp b/example/pretty/pretty.cpp index b09fc787..cfb3f0fd 100644 --- a/example/pretty/pretty.cpp +++ b/example/pretty/pretty.cpp @@ -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;
}
diff --git a/example/prettyauto/prettyauto.cpp b/example/prettyauto/prettyauto.cpp index 2e52e9e9..3f85f405 100644 --- a/example/prettyauto/prettyauto.cpp +++ b/example/prettyauto/prettyauto.cpp @@ -7,6 +7,7 @@ #include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/encodedstream.h" // NEW
+#include "rapidjson/error/en.h"
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
@@ -47,7 +48,7 @@ int main(int, char*[]) { // JSON reader parse from the input stream and let writer generate the output.
//if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
if (!reader.Parse<kParseValidateEncodingFlag>(eis, writer)) { // CHANGED
- 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;
}
|