From f4ea0d3f640fc29e857cc2f187cef75bc2a035a5 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Fri, 15 Apr 2016 10:43:14 +0800 Subject: [PATCH] Added documentation for kParseNumbersAsStringsFlag --- doc/dom.md | 1 + doc/dom.zh-cn.md | 1 + doc/sax.md | 4 +++- doc/sax.zh-cn.md | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/dom.md b/doc/dom.md index 79b6817..6cccf08 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -116,6 +116,7 @@ Parse flags | Meaning `kParseStopWhenDoneFlag` | After parsing a complete JSON root from stream, stop further processing the rest of stream. When this flag is used, parser will not generate `kParseErrorDocumentRootNotSingular` error. Using this flag for parsing multiple JSONs in the same stream. `kParseFullPrecisionFlag` | Parse number in full precision (slower). If this flag is not set, the normal precision (faster) is used. Normal precision has maximum 3 [ULP](http://en.wikipedia.org/wiki/Unit_in_the_last_place) error. `kParseCommentsFlag` | Allow one-line `// ...` and multi-line `/* ... */` comments (relaxed JSON syntax). +`kParseNumbersAsStringsFlag` | Parse numerical type values as strings. `kParseTrailingCommasFlag` | Allow trailing commas at the end of objects and arrays (relaxed JSON syntax). By using a non-type template parameter, instead of a function parameter, C++ compiler can generate code which is optimized for specified combinations, improving speed, and reducing code size (if only using a single specialization). The downside is the flags needed to be determined in compile-time. diff --git a/doc/dom.zh-cn.md b/doc/dom.zh-cn.md index 30266a3..df6815e 100644 --- a/doc/dom.zh-cn.md +++ b/doc/dom.zh-cn.md @@ -116,6 +116,7 @@ GenericDocument& GenericDocument::Parse(const Ch* str); `kParseStopWhenDoneFlag` | 当从流解析了一个完整的JSON根节点之后,停止继续处理余下的流。当使用了此标志,解析器便不会产生`kParseErrorDocumentRootNotSingular`错误。可使用本标志去解析同一个流里的多个JSON。 `kParseFullPrecisionFlag` | 使用完整的精确度去解析数字(较慢)。如不设置此标节,则会使用正常的精确度(较快)。正常精确度会有最多3个[ULP](http://en.wikipedia.org/wiki/Unit_in_the_last_place)的误差。 `kParseCommentsFlag` | 容许单行 `// ...` 及多行 `/* ... */` 注释(放宽的JSON语法)。 +`kParseNumbersAsStringsFlag` | 把数字类型解析成字符串。 `kParseTrailingCommasFlag` | 容许在对象和数组结束前含有逗号(放宽的JSON语法)。 由于使用了非类型模板参数,而不是函数参数,C++编译器能为个别组合生成代码,以改善性能及减少代码尺寸(当只用单种特化)。缺点是需要在编译期决定标志。 diff --git a/doc/sax.md b/doc/sax.md index 9a6d814..9d4f202 100644 --- a/doc/sax.md +++ b/doc/sax.md @@ -106,6 +106,7 @@ class Handler { bool Int64(int64_t i); bool Uint64(uint64_t i); bool Double(double d); + bool RawNumber(const Ch* str, SizeType length, bool copy); bool String(const Ch* str, SizeType length, bool copy); bool StartObject(); bool Key(const Ch* str, SizeType length, bool copy); @@ -119,7 +120,7 @@ class Handler { `Bool(bool)` is called when the `Reader` encounters a JSON true or false value. -When the `Reader` encounters a JSON number, it chooses a suitable C++ type mapping. And then it calls *one* function out of `Int(int)`, `Uint(unsigned)`, `Int64(int64_t)`, `Uint64(uint64_t)` and `Double(double)`. +When the `Reader` encounters a JSON number, it chooses a suitable C++ type mapping. And then it calls *one* function out of `Int(int)`, `Uint(unsigned)`, `Int64(int64_t)`, `Uint64(uint64_t)` and `Double(double)`. If `kParseNumbersAsStrings` is enabled, `Reader` will always calls `RawNumber()` instead. `String(const char* str, SizeType length, bool copy)` is called when the `Reader` encounters a string. The first parameter is pointer to the string. The second parameter is the length of the string (excluding the null terminator). Note that RapidJSON supports null character `'\0'` inside a string. If such situation happens, `strlen(str) < length`. The last `copy` indicates whether the handler needs to make a copy of the string. For normal parsing, `copy = true`. Only when *insitu* parsing is used, `copy = false`. And beware that, the character type depends on the target encoding, which will be explained later. @@ -419,6 +420,7 @@ struct CapitalizeFilter { bool Int64(int64_t i) { return out_.Int64(i); } bool Uint64(uint64_t u) { return out_.Uint64(u); } bool Double(double d) { return out_.Double(d); } + bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); } bool String(const char* str, SizeType length, bool) { buffer_.clear(); for (SizeType i = 0; i < length; i++) diff --git a/doc/sax.zh-cn.md b/doc/sax.zh-cn.md index f8dc7b9..47306f6 100644 --- a/doc/sax.zh-cn.md +++ b/doc/sax.zh-cn.md @@ -119,7 +119,7 @@ class Handler { 当`Reader`遇到JSON true或false值时会调用`Bool(bool)`。 -当`Reader`遇到JSON number,它会选择一个合适的C++类型映射,然后调用`Int(int)`、`Uint(unsigned)`、`Int64(int64_t)`、`Uint64(uint64_t)`及`Double(double)`的*其中之一个*。 +当`Reader`遇到JSON number,它会选择一个合适的C++类型映射,然后调用`Int(int)`、`Uint(unsigned)`、`Int64(int64_t)`、`Uint64(uint64_t)`及`Double(double)`的*其中之一个*。 若开启了 `kParseNumbersAsStrings` 选项,`Reader` 便会改为调用 `RawNumber()`。 当`Reader`遇到JSON string,它会调用`String(const char* str, SizeType length, bool copy)`。第一个参数是字符串的指针。第二个参数是字符串的长度(不包含空终止符号)。注意RapidJSON支持字串中含有空字符`'\0'`。若出现这种情况,便会有`strlen(str) < length`。最后的`copy`参数表示处理器是否需要复制该字符串。在正常解析时,`copy = true`。仅当使用原位解析时,`copy = false`。此外,还要注意字符的类型与目标编码相关,我们稍后会再谈这一点。 @@ -419,6 +419,7 @@ struct CapitalizeFilter { bool Int64(int64_t i) { return out_.Int64(i); } bool Uint64(uint64_t u) { return out_.Uint64(u); } bool Double(double d) { return out_.Double(d); } + bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); } bool String(const char* str, SizeType length, bool) { buffer_.clear(); for (SizeType i = 0; i < length; i++)