rj_schema 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (299) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +18 -0
  3. data/ext/rj_schema/extconf.rb +7 -0
  4. data/ext/rj_schema/rapidjson/CHANGELOG.md +158 -0
  5. data/ext/rj_schema/rapidjson/CMakeLists.txt +221 -0
  6. data/ext/rj_schema/rapidjson/CMakeModules/FindGTestSrc.cmake +30 -0
  7. data/ext/rj_schema/rapidjson/RapidJSON.pc.in +7 -0
  8. data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +15 -0
  9. data/ext/rj_schema/rapidjson/RapidJSONConfigVersion.cmake.in +10 -0
  10. data/ext/rj_schema/rapidjson/appveyor.yml +41 -0
  11. data/ext/rj_schema/rapidjson/bin/data/glossary.json +22 -0
  12. data/ext/rj_schema/rapidjson/bin/data/menu.json +27 -0
  13. data/ext/rj_schema/rapidjson/bin/data/readme.txt +1 -0
  14. data/ext/rj_schema/rapidjson/bin/data/sample.json +3315 -0
  15. data/ext/rj_schema/rapidjson/bin/data/webapp.json +88 -0
  16. data/ext/rj_schema/rapidjson/bin/data/widget.json +26 -0
  17. data/ext/rj_schema/rapidjson/bin/draft-04/schema +150 -0
  18. data/ext/rj_schema/rapidjson/bin/encodings/utf16be.json +0 -0
  19. data/ext/rj_schema/rapidjson/bin/encodings/utf16bebom.json +0 -0
  20. data/ext/rj_schema/rapidjson/bin/encodings/utf16le.json +0 -0
  21. data/ext/rj_schema/rapidjson/bin/encodings/utf16lebom.json +0 -0
  22. data/ext/rj_schema/rapidjson/bin/encodings/utf32be.json +0 -0
  23. data/ext/rj_schema/rapidjson/bin/encodings/utf32bebom.json +0 -0
  24. data/ext/rj_schema/rapidjson/bin/encodings/utf32le.json +0 -0
  25. data/ext/rj_schema/rapidjson/bin/encodings/utf32lebom.json +0 -0
  26. data/ext/rj_schema/rapidjson/bin/encodings/utf8.json +7 -0
  27. data/ext/rj_schema/rapidjson/bin/encodings/utf8bom.json +7 -0
  28. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail1.json +1 -0
  29. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail10.json +1 -0
  30. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail11.json +1 -0
  31. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail12.json +1 -0
  32. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail13.json +1 -0
  33. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail14.json +1 -0
  34. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail15.json +1 -0
  35. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail16.json +1 -0
  36. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail17.json +1 -0
  37. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail18.json +1 -0
  38. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail19.json +1 -0
  39. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail2.json +1 -0
  40. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail20.json +1 -0
  41. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail21.json +1 -0
  42. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail22.json +1 -0
  43. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail23.json +1 -0
  44. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail24.json +1 -0
  45. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail25.json +1 -0
  46. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail26.json +1 -0
  47. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail27.json +2 -0
  48. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail28.json +2 -0
  49. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail29.json +1 -0
  50. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail3.json +1 -0
  51. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail30.json +1 -0
  52. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail31.json +1 -0
  53. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail32.json +1 -0
  54. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail33.json +1 -0
  55. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail4.json +1 -0
  56. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail5.json +1 -0
  57. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail6.json +1 -0
  58. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail7.json +1 -0
  59. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail8.json +1 -0
  60. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail9.json +1 -0
  61. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass1.json +58 -0
  62. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass2.json +1 -0
  63. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass3.json +6 -0
  64. data/ext/rj_schema/rapidjson/bin/jsonchecker/readme.txt +3 -0
  65. data/ext/rj_schema/rapidjson/bin/jsonschema/LICENSE +19 -0
  66. data/ext/rj_schema/rapidjson/bin/jsonschema/README.md +148 -0
  67. data/ext/rj_schema/rapidjson/bin/jsonschema/bin/jsonschema_suite +283 -0
  68. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/folder/folderInteger.json +3 -0
  69. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/integer.json +3 -0
  70. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/subSchemas.json +8 -0
  71. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalItems.json +82 -0
  72. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalProperties.json +88 -0
  73. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/default.json +49 -0
  74. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/dependencies.json +108 -0
  75. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/disallow.json +80 -0
  76. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/divisibleBy.json +60 -0
  77. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/enum.json +71 -0
  78. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/extends.json +94 -0
  79. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/items.json +46 -0
  80. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxItems.json +28 -0
  81. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxLength.json +33 -0
  82. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maximum.json +42 -0
  83. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minItems.json +28 -0
  84. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minLength.json +33 -0
  85. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minimum.json +42 -0
  86. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/bignum.json +107 -0
  87. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/format.json +222 -0
  88. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/jsregex.json +18 -0
  89. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json +15 -0
  90. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/pattern.json +34 -0
  91. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/patternProperties.json +110 -0
  92. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/properties.json +92 -0
  93. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/ref.json +159 -0
  94. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/refRemote.json +74 -0
  95. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/required.json +53 -0
  96. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/type.json +474 -0
  97. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/uniqueItems.json +79 -0
  98. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalItems.json +82 -0
  99. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalProperties.json +88 -0
  100. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/allOf.json +112 -0
  101. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/anyOf.json +68 -0
  102. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/default.json +49 -0
  103. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/definitions.json +32 -0
  104. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/dependencies.json +113 -0
  105. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/enum.json +72 -0
  106. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/items.json +46 -0
  107. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxItems.json +28 -0
  108. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxLength.json +33 -0
  109. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxProperties.json +28 -0
  110. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maximum.json +42 -0
  111. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minItems.json +28 -0
  112. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minLength.json +33 -0
  113. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minProperties.json +28 -0
  114. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minimum.json +42 -0
  115. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/multipleOf.json +60 -0
  116. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/not.json +96 -0
  117. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/oneOf.json +68 -0
  118. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/bignum.json +107 -0
  119. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/format.json +148 -0
  120. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json +15 -0
  121. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/pattern.json +34 -0
  122. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/patternProperties.json +110 -0
  123. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/properties.json +92 -0
  124. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/ref.json +159 -0
  125. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/refRemote.json +74 -0
  126. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/required.json +39 -0
  127. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/type.json +330 -0
  128. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/uniqueItems.json +79 -0
  129. data/ext/rj_schema/rapidjson/bin/jsonschema/tox.ini +8 -0
  130. data/ext/rj_schema/rapidjson/bin/types/booleans.json +102 -0
  131. data/ext/rj_schema/rapidjson/bin/types/floats.json +102 -0
  132. data/ext/rj_schema/rapidjson/bin/types/guids.json +102 -0
  133. data/ext/rj_schema/rapidjson/bin/types/integers.json +102 -0
  134. data/ext/rj_schema/rapidjson/bin/types/mixed.json +592 -0
  135. data/ext/rj_schema/rapidjson/bin/types/nulls.json +102 -0
  136. data/ext/rj_schema/rapidjson/bin/types/paragraphs.json +102 -0
  137. data/ext/rj_schema/rapidjson/bin/types/readme.txt +1 -0
  138. data/ext/rj_schema/rapidjson/contrib/natvis/LICENSE +45 -0
  139. data/ext/rj_schema/rapidjson/contrib/natvis/README.md +7 -0
  140. data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +38 -0
  141. data/ext/rj_schema/rapidjson/doc/CMakeLists.txt +27 -0
  142. data/ext/rj_schema/rapidjson/doc/Doxyfile.in +2369 -0
  143. data/ext/rj_schema/rapidjson/doc/Doxyfile.zh-cn.in +2369 -0
  144. data/ext/rj_schema/rapidjson/doc/diagram/architecture.dot +50 -0
  145. data/ext/rj_schema/rapidjson/doc/diagram/architecture.png +0 -0
  146. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.dot +65 -0
  147. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.png +0 -0
  148. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.dot +62 -0
  149. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.png +0 -0
  150. data/ext/rj_schema/rapidjson/doc/diagram/makefile +8 -0
  151. data/ext/rj_schema/rapidjson/doc/diagram/move1.dot +47 -0
  152. data/ext/rj_schema/rapidjson/doc/diagram/move1.png +0 -0
  153. data/ext/rj_schema/rapidjson/doc/diagram/move2.dot +62 -0
  154. data/ext/rj_schema/rapidjson/doc/diagram/move2.png +0 -0
  155. data/ext/rj_schema/rapidjson/doc/diagram/move3.dot +60 -0
  156. data/ext/rj_schema/rapidjson/doc/diagram/move3.png +0 -0
  157. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.dot +56 -0
  158. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.png +0 -0
  159. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.dot +54 -0
  160. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.png +0 -0
  161. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.dot +58 -0
  162. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.png +0 -0
  163. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.dot +73 -0
  164. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.png +0 -0
  165. data/ext/rj_schema/rapidjson/doc/dom.md +280 -0
  166. data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +284 -0
  167. data/ext/rj_schema/rapidjson/doc/encoding.md +146 -0
  168. data/ext/rj_schema/rapidjson/doc/encoding.zh-cn.md +152 -0
  169. data/ext/rj_schema/rapidjson/doc/faq.md +289 -0
  170. data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +290 -0
  171. data/ext/rj_schema/rapidjson/doc/features.md +104 -0
  172. data/ext/rj_schema/rapidjson/doc/features.zh-cn.md +103 -0
  173. data/ext/rj_schema/rapidjson/doc/internals.md +368 -0
  174. data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +363 -0
  175. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.png +0 -0
  176. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.svg +119 -0
  177. data/ext/rj_schema/rapidjson/doc/misc/DoxygenLayout.xml +194 -0
  178. data/ext/rj_schema/rapidjson/doc/misc/doxygenextra.css +274 -0
  179. data/ext/rj_schema/rapidjson/doc/misc/footer.html +11 -0
  180. data/ext/rj_schema/rapidjson/doc/misc/header.html +24 -0
  181. data/ext/rj_schema/rapidjson/doc/npm.md +31 -0
  182. data/ext/rj_schema/rapidjson/doc/performance.md +26 -0
  183. data/ext/rj_schema/rapidjson/doc/performance.zh-cn.md +26 -0
  184. data/ext/rj_schema/rapidjson/doc/pointer.md +234 -0
  185. data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +234 -0
  186. data/ext/rj_schema/rapidjson/doc/sax.md +509 -0
  187. data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +487 -0
  188. data/ext/rj_schema/rapidjson/doc/schema.md +505 -0
  189. data/ext/rj_schema/rapidjson/doc/schema.zh-cn.md +237 -0
  190. data/ext/rj_schema/rapidjson/doc/stream.md +426 -0
  191. data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +426 -0
  192. data/ext/rj_schema/rapidjson/doc/tutorial.md +536 -0
  193. data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +534 -0
  194. data/ext/rj_schema/rapidjson/docker/debian/Dockerfile +8 -0
  195. data/ext/rj_schema/rapidjson/example/CMakeLists.txt +45 -0
  196. data/ext/rj_schema/rapidjson/example/archiver/archiver.cpp +292 -0
  197. data/ext/rj_schema/rapidjson/example/archiver/archiver.h +145 -0
  198. data/ext/rj_schema/rapidjson/example/archiver/archivertest.cpp +287 -0
  199. data/ext/rj_schema/rapidjson/example/capitalize/capitalize.cpp +67 -0
  200. data/ext/rj_schema/rapidjson/example/condense/condense.cpp +32 -0
  201. data/ext/rj_schema/rapidjson/example/filterkey/filterkey.cpp +135 -0
  202. data/ext/rj_schema/rapidjson/example/filterkeydom/filterkeydom.cpp +170 -0
  203. data/ext/rj_schema/rapidjson/example/jsonx/jsonx.cpp +207 -0
  204. data/ext/rj_schema/rapidjson/example/lookaheadparser/lookaheadparser.cpp +350 -0
  205. data/ext/rj_schema/rapidjson/example/messagereader/messagereader.cpp +105 -0
  206. data/ext/rj_schema/rapidjson/example/parsebyparts/parsebyparts.cpp +176 -0
  207. data/ext/rj_schema/rapidjson/example/pretty/pretty.cpp +30 -0
  208. data/ext/rj_schema/rapidjson/example/prettyauto/prettyauto.cpp +56 -0
  209. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +78 -0
  210. data/ext/rj_schema/rapidjson/example/serialize/serialize.cpp +173 -0
  211. data/ext/rj_schema/rapidjson/example/simpledom/simpledom.cpp +29 -0
  212. data/ext/rj_schema/rapidjson/example/simplepullreader/simplepullreader.cpp +53 -0
  213. data/ext/rj_schema/rapidjson/example/simplereader/simplereader.cpp +42 -0
  214. data/ext/rj_schema/rapidjson/example/simplewriter/simplewriter.cpp +36 -0
  215. data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +151 -0
  216. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +271 -0
  217. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
  218. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +2630 -0
  219. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +299 -0
  220. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +716 -0
  221. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +74 -0
  222. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +161 -0
  223. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +99 -0
  224. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +104 -0
  225. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +151 -0
  226. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +290 -0
  227. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +258 -0
  228. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +245 -0
  229. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
  230. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +304 -0
  231. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +181 -0
  232. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +55 -0
  233. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +734 -0
  234. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +231 -0
  235. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +69 -0
  236. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +269 -0
  237. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +46 -0
  238. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +115 -0
  239. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +70 -0
  240. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +71 -0
  241. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
  242. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
  243. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
  244. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1363 -0
  245. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +277 -0
  246. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +628 -0
  247. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +2222 -0
  248. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +2479 -0
  249. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +223 -0
  250. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +121 -0
  251. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +716 -0
  252. data/ext/rj_schema/rapidjson/include_dirs.js +2 -0
  253. data/ext/rj_schema/rapidjson/library.json +15 -0
  254. data/ext/rj_schema/rapidjson/license.txt +57 -0
  255. data/ext/rj_schema/rapidjson/package.json +24 -0
  256. data/ext/rj_schema/rapidjson/rapidjson.autopkg +77 -0
  257. data/ext/rj_schema/rapidjson/readme.md +160 -0
  258. data/ext/rj_schema/rapidjson/readme.zh-cn.md +152 -0
  259. data/ext/rj_schema/rapidjson/test/CMakeLists.txt +20 -0
  260. data/ext/rj_schema/rapidjson/test/perftest/CMakeLists.txt +28 -0
  261. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +974 -0
  262. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +24 -0
  263. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +185 -0
  264. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +166 -0
  265. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +472 -0
  266. data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +216 -0
  267. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +92 -0
  268. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +102 -0
  269. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +133 -0
  270. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +115 -0
  271. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +672 -0
  272. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +98 -0
  273. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +313 -0
  274. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +451 -0
  275. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +112 -0
  276. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +230 -0
  277. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +181 -0
  278. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +160 -0
  279. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +143 -0
  280. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +70 -0
  281. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +92 -0
  282. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +1529 -0
  283. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +344 -0
  284. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +1895 -0
  285. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +638 -0
  286. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +2009 -0
  287. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +219 -0
  288. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +30 -0
  289. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +192 -0
  290. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +132 -0
  291. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +51 -0
  292. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +140 -0
  293. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1829 -0
  294. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +598 -0
  295. data/ext/rj_schema/rapidjson/test/valgrind.supp +17 -0
  296. data/ext/rj_schema/rapidjson/travis-doxygen.sh +121 -0
  297. data/ext/rj_schema/rj_schema.cpp +136 -0
  298. data/lib/rj_schema.rb +7 -0
  299. metadata +371 -0
@@ -0,0 +1,509 @@
1
+ # SAX
2
+
3
+ The term "SAX" originated from [Simple API for XML](http://en.wikipedia.org/wiki/Simple_API_for_XML). We borrowed this term for JSON parsing and generation.
4
+
5
+ In RapidJSON, `Reader` (typedef of `GenericReader<...>`) is the SAX-style parser for JSON, and `Writer` (typedef of `GenericWriter<...>`) is the SAX-style generator for JSON.
6
+
7
+ [TOC]
8
+
9
+ # Reader {#Reader}
10
+
11
+ `Reader` parses a JSON from a stream. While it reads characters from the stream, it analyzes the characters according to the syntax of JSON, and publishes events to a handler.
12
+
13
+ For example, here is a JSON.
14
+
15
+ ~~~~~~~~~~js
16
+ {
17
+ "hello": "world",
18
+ "t": true ,
19
+ "f": false,
20
+ "n": null,
21
+ "i": 123,
22
+ "pi": 3.1416,
23
+ "a": [1, 2, 3, 4]
24
+ }
25
+ ~~~~~~~~~~
26
+
27
+ When a `Reader` parses this JSON, it publishes the following events to the handler sequentially:
28
+
29
+ ~~~~~~~~~~
30
+ StartObject()
31
+ Key("hello", 5, true)
32
+ String("world", 5, true)
33
+ Key("t", 1, true)
34
+ Bool(true)
35
+ Key("f", 1, true)
36
+ Bool(false)
37
+ Key("n", 1, true)
38
+ Null()
39
+ Key("i")
40
+ UInt(123)
41
+ Key("pi")
42
+ Double(3.1416)
43
+ Key("a")
44
+ StartArray()
45
+ Uint(1)
46
+ Uint(2)
47
+ Uint(3)
48
+ Uint(4)
49
+ EndArray(4)
50
+ EndObject(7)
51
+ ~~~~~~~~~~
52
+
53
+ These events can be easily matched with the JSON, but some event parameters need further explanation. Let's see the `simplereader` example which produces exactly the same output as above:
54
+
55
+ ~~~~~~~~~~cpp
56
+ #include "rapidjson/reader.h"
57
+ #include <iostream>
58
+
59
+ using namespace rapidjson;
60
+ using namespace std;
61
+
62
+ struct MyHandler : public BaseReaderHandler<UTF8<>, MyHandler> {
63
+ bool Null() { cout << "Null()" << endl; return true; }
64
+ bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; }
65
+ bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; }
66
+ bool Uint(unsigned u) { cout << "Uint(" << u << ")" << endl; return true; }
67
+ bool Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; return true; }
68
+ bool Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; }
69
+ bool Double(double d) { cout << "Double(" << d << ")" << endl; return true; }
70
+ bool String(const char* str, SizeType length, bool copy) {
71
+ cout << "String(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl;
72
+ return true;
73
+ }
74
+ bool StartObject() { cout << "StartObject()" << endl; return true; }
75
+ bool Key(const char* str, SizeType length, bool copy) {
76
+ cout << "Key(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl;
77
+ return true;
78
+ }
79
+ bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; }
80
+ bool StartArray() { cout << "StartArray()" << endl; return true; }
81
+ bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; }
82
+ };
83
+
84
+ void main() {
85
+ const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
86
+
87
+ MyHandler handler;
88
+ Reader reader;
89
+ StringStream ss(json);
90
+ reader.Parse(ss, handler);
91
+ }
92
+ ~~~~~~~~~~
93
+
94
+ Note that RapidJSON uses templates to statically bind the `Reader` type and the handler type, instead of using classes with virtual functions. This paradigm can improve performance by inlining functions.
95
+
96
+ ## Handler {#Handler}
97
+
98
+ As shown in the previous example, the user needs to implement a handler which consumes the events (via function calls) from the `Reader`. The handler must contain the following member functions.
99
+
100
+ ~~~~~~~~~~cpp
101
+ class Handler {
102
+ bool Null();
103
+ bool Bool(bool b);
104
+ bool Int(int i);
105
+ bool Uint(unsigned i);
106
+ bool Int64(int64_t i);
107
+ bool Uint64(uint64_t i);
108
+ bool Double(double d);
109
+ bool RawNumber(const Ch* str, SizeType length, bool copy);
110
+ bool String(const Ch* str, SizeType length, bool copy);
111
+ bool StartObject();
112
+ bool Key(const Ch* str, SizeType length, bool copy);
113
+ bool EndObject(SizeType memberCount);
114
+ bool StartArray();
115
+ bool EndArray(SizeType elementCount);
116
+ };
117
+ ~~~~~~~~~~
118
+
119
+ `Null()` is called when the `Reader` encounters a JSON null value.
120
+
121
+ `Bool(bool)` is called when the `Reader` encounters a JSON true or false value.
122
+
123
+ 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.
124
+
125
+ `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 be aware that the character type depends on the target encoding, which will be explained later.
126
+
127
+ When the `Reader` encounters the beginning of an object, it calls `StartObject()`. An object in JSON is a set of name-value pairs. If the object contains members it first calls `Key()` for the name of member, and then calls functions depending on the type of the value. These calls of name-value pairs repeat until calling `EndObject(SizeType memberCount)`. Note that the `memberCount` parameter is just an aid for the handler; users who do not need this parameter may ignore it.
128
+
129
+ Arrays are similar to objects, but simpler. At the beginning of an array, the `Reader` calls `BeginArray()`. If there is elements, it calls functions according to the types of element. Similarly, in the last call `EndArray(SizeType elementCount)`, the parameter `elementCount` is just an aid for the handler.
130
+
131
+ Every handler function returns a `bool`. Normally it should return `true`. If the handler encounters an error, it can return `false` to notify the event publisher to stop further processing.
132
+
133
+ For example, when we parse a JSON with `Reader` and the handler detects that the JSON does not conform to the required schema, the handler can return `false` and let the `Reader` stop further parsing. This will place the `Reader` in an error state, with error code `kParseErrorTermination`.
134
+
135
+ ## GenericReader {#GenericReader}
136
+
137
+ As mentioned before, `Reader` is a typedef of a template class `GenericReader`:
138
+
139
+ ~~~~~~~~~~cpp
140
+ namespace rapidjson {
141
+
142
+ template <typename SourceEncoding, typename TargetEncoding, typename Allocator = MemoryPoolAllocator<> >
143
+ class GenericReader {
144
+ // ...
145
+ };
146
+
147
+ typedef GenericReader<UTF8<>, UTF8<> > Reader;
148
+
149
+ } // namespace rapidjson
150
+ ~~~~~~~~~~
151
+
152
+ The `Reader` uses UTF-8 as both source and target encoding. The source encoding means the encoding in the JSON stream. The target encoding means the encoding of the `str` parameter in `String()` calls. For example, to parse a UTF-8 stream and output UTF-16 string events, you can define a reader by:
153
+
154
+ ~~~~~~~~~~cpp
155
+ GenericReader<UTF8<>, UTF16<> > reader;
156
+ ~~~~~~~~~~
157
+
158
+ Note that, the default character type of `UTF16` is `wchar_t`. So this `reader` needs to call `String(const wchar_t*, SizeType, bool)` of the handler.
159
+
160
+ The third template parameter `Allocator` is the allocator type for internal data structure (actually a stack).
161
+
162
+ ## Parsing {#SaxParsing}
163
+
164
+ The main function of `Reader` is used to parse JSON.
165
+
166
+ ~~~~~~~~~~cpp
167
+ template <unsigned parseFlags, typename InputStream, typename Handler>
168
+ bool Parse(InputStream& is, Handler& handler);
169
+
170
+ // with parseFlags = kDefaultParseFlags
171
+ template <typename InputStream, typename Handler>
172
+ bool Parse(InputStream& is, Handler& handler);
173
+ ~~~~~~~~~~
174
+
175
+ If an error occurs during parsing, it will return `false`. User can also call `bool HasParseError()`, `ParseErrorCode GetParseErrorCode()` and `size_t GetErrorOffset()` to obtain the error states. In fact, `Document` uses these `Reader` functions to obtain parse errors. Please refer to [DOM](doc/dom.md) for details about parse errors.
176
+
177
+ ## Token-by-Token Parsing {#TokenByTokenParsing}
178
+
179
+ Some users may wish to parse a JSON input stream a single token at a time, instead of immediately parsing an entire document without stopping. To parse JSON this way, instead of calling `Parse`, you can use the `IterativeParse` set of functions:
180
+
181
+ ~~~~~~~~~~cpp
182
+ void IterativeParseInit();
183
+
184
+ template <unsigned parseFlags, typename InputStream, typename Handler>
185
+ bool IterativeParseNext(InputStream& is, Handler& handler);
186
+
187
+ bool IterativeParseComplete();
188
+ ~~~~~~~~~~
189
+
190
+ Here is an example of iteratively parsing JSON, token by token:
191
+
192
+ ~~~~~~~~~~cpp
193
+ reader.IterativeParseInit();
194
+ while (!reader.IterativeParseComplete()) {
195
+ reader.IterativeParseNext<kParseDefaultFlags>(is, handler);
196
+ // Your handler has been called once.
197
+ }
198
+ ~~~~~~~~~~
199
+
200
+ # Writer {#Writer}
201
+
202
+ `Reader` converts (parses) JSON into events. `Writer` does exactly the opposite. It converts events into JSON.
203
+
204
+ `Writer` is very easy to use. If your application only need to converts some data into JSON, it may be a good choice to use `Writer` directly, instead of building a `Document` and then stringifying it with a `Writer`.
205
+
206
+ In `simplewriter` example, we do exactly the reverse of `simplereader`.
207
+
208
+ ~~~~~~~~~~cpp
209
+ #include "rapidjson/writer.h"
210
+ #include "rapidjson/stringbuffer.h"
211
+ #include <iostream>
212
+
213
+ using namespace rapidjson;
214
+ using namespace std;
215
+
216
+ void main() {
217
+ StringBuffer s;
218
+ Writer<StringBuffer> writer(s);
219
+
220
+ writer.StartObject();
221
+ writer.Key("hello");
222
+ writer.String("world");
223
+ writer.Key("t");
224
+ writer.Bool(true);
225
+ writer.Key("f");
226
+ writer.Bool(false);
227
+ writer.Key("n");
228
+ writer.Null();
229
+ writer.Key("i");
230
+ writer.Uint(123);
231
+ writer.Key("pi");
232
+ writer.Double(3.1416);
233
+ writer.Key("a");
234
+ writer.StartArray();
235
+ for (unsigned i = 0; i < 4; i++)
236
+ writer.Uint(i);
237
+ writer.EndArray();
238
+ writer.EndObject();
239
+
240
+ cout << s.GetString() << endl;
241
+ }
242
+ ~~~~~~~~~~
243
+
244
+ ~~~~~~~~~~
245
+ {"hello":"world","t":true,"f":false,"n":null,"i":123,"pi":3.1416,"a":[0,1,2,3]}
246
+ ~~~~~~~~~~
247
+
248
+ There are two `String()` and `Key()` overloads. One is the same as defined in handler concept with 3 parameters. It can handle string with null characters. Another one is the simpler version used in the above example.
249
+
250
+ Note that, the example code does not pass any parameters in `EndArray()` and `EndObject()`. An `SizeType` can be passed but it will be simply ignored by `Writer`.
251
+
252
+ You may doubt that, why not just using `sprintf()` or `std::stringstream` to build a JSON?
253
+
254
+ There are various reasons:
255
+ 1. `Writer` must output a well-formed JSON. If there is incorrect event sequence (e.g. `Int()` just after `StartObject()`), it generates assertion fail in debug mode.
256
+ 2. `Writer::String()` can handle string escaping (e.g. converting code point `U+000A` to `\n`) and Unicode transcoding.
257
+ 3. `Writer` handles number output consistently.
258
+ 4. `Writer` implements the event handler concept. It can be used to handle events from `Reader`, `Document` or other event publisher.
259
+ 5. `Writer` can be optimized for different platforms.
260
+
261
+ Anyway, using `Writer` API is even simpler than generating a JSON by ad hoc methods.
262
+
263
+ ## Template {#WriterTemplate}
264
+
265
+ `Writer` has a minor design difference to `Reader`. `Writer` is a template class, not a typedef. There is no `GenericWriter`. The following is the declaration.
266
+
267
+ ~~~~~~~~~~cpp
268
+ namespace rapidjson {
269
+
270
+ template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename Allocator = CrtAllocator<>, unsigned writeFlags = kWriteDefaultFlags>
271
+ class Writer {
272
+ public:
273
+ Writer(OutputStream& os, Allocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth)
274
+ // ...
275
+ };
276
+
277
+ } // namespace rapidjson
278
+ ~~~~~~~~~~
279
+
280
+ The `OutputStream` template parameter is the type of output stream. It cannot be deduced and must be specified by user.
281
+
282
+ The `SourceEncoding` template parameter specifies the encoding to be used in `String(const Ch*, ...)`.
283
+
284
+ The `TargetEncoding` template parameter specifies the encoding in the output stream.
285
+
286
+ The `Allocator` is the type of allocator, which is used for allocating internal data structure (a stack).
287
+
288
+ The `writeFlags` are combination of the following bit-flags:
289
+
290
+ Parse flags | Meaning
291
+ ------------------------------|-----------------------------------
292
+ `kWriteNoFlags` | No flag is set.
293
+ `kWriteDefaultFlags` | Default write flags. It is equal to macro `RAPIDJSON_WRITE_DEFAULT_FLAGS`, which is defined as `kWriteNoFlags`.
294
+ `kWriteValidateEncodingFlag` | Validate encoding of JSON strings.
295
+ `kWriteNanAndInfFlag` | Allow writing of `Infinity`, `-Infinity` and `NaN`.
296
+
297
+ Besides, the constructor of `Writer` has a `levelDepth` parameter. This parameter affects the initial memory allocated for storing information per hierarchy level.
298
+
299
+ ## PrettyWriter {#PrettyWriter}
300
+
301
+ While the output of `Writer` is the most condensed JSON without white-spaces, suitable for network transfer or storage, it is not easily readable by human.
302
+
303
+ Therefore, RapidJSON provides a `PrettyWriter`, which adds indentation and line feeds in the output.
304
+
305
+ The usage of `PrettyWriter` is exactly the same as `Writer`, expect that `PrettyWriter` provides a `SetIndent(Ch indentChar, unsigned indentCharCount)` function. The default is 4 spaces.
306
+
307
+ ## Completeness and Reset {#CompletenessReset}
308
+
309
+ A `Writer` can only output a single JSON, which can be any JSON type at the root. Once the singular event for root (e.g. `String()`), or the last matching `EndObject()` or `EndArray()` event, is handled, the output JSON is well-formed and complete. User can detect this state by calling `Writer::IsComplete()`.
310
+
311
+ When a JSON is complete, the `Writer` cannot accept any new events. Otherwise the output will be invalid (i.e. having more than one root). To reuse the `Writer` object, user can call `Writer::Reset(OutputStream& os)` to reset all internal states of the `Writer` with a new output stream.
312
+
313
+ # Techniques {#SaxTechniques}
314
+
315
+ ## Parsing JSON to Custom Data Structure {#CustomDataStructure}
316
+
317
+ `Document`'s parsing capability is completely based on `Reader`. Actually `Document` is a handler which receives events from a reader to build a DOM during parsing.
318
+
319
+ User may uses `Reader` to build other data structures directly. This eliminates building of DOM, thus reducing memory and improving performance.
320
+
321
+ In the following `messagereader` example, `ParseMessages()` parses a JSON which should be an object with key-string pairs.
322
+
323
+ ~~~~~~~~~~cpp
324
+ #include "rapidjson/reader.h"
325
+ #include "rapidjson/error/en.h"
326
+ #include <iostream>
327
+ #include <string>
328
+ #include <map>
329
+
330
+ using namespace std;
331
+ using namespace rapidjson;
332
+
333
+ typedef map<string, string> MessageMap;
334
+
335
+ struct MessageHandler
336
+ : public BaseReaderHandler<UTF8<>, MessageHandler> {
337
+ MessageHandler() : state_(kExpectObjectStart) {
338
+ }
339
+
340
+ bool StartObject() {
341
+ switch (state_) {
342
+ case kExpectObjectStart:
343
+ state_ = kExpectNameOrObjectEnd;
344
+ return true;
345
+ default:
346
+ return false;
347
+ }
348
+ }
349
+
350
+ bool String(const char* str, SizeType length, bool) {
351
+ switch (state_) {
352
+ case kExpectNameOrObjectEnd:
353
+ name_ = string(str, length);
354
+ state_ = kExpectValue;
355
+ return true;
356
+ case kExpectValue:
357
+ messages_.insert(MessageMap::value_type(name_, string(str, length)));
358
+ state_ = kExpectNameOrObjectEnd;
359
+ return true;
360
+ default:
361
+ return false;
362
+ }
363
+ }
364
+
365
+ bool EndObject(SizeType) { return state_ == kExpectNameOrObjectEnd; }
366
+
367
+ bool Default() { return false; } // All other events are invalid.
368
+
369
+ MessageMap messages_;
370
+ enum State {
371
+ kExpectObjectStart,
372
+ kExpectNameOrObjectEnd,
373
+ kExpectValue,
374
+ }state_;
375
+ std::string name_;
376
+ };
377
+
378
+ void ParseMessages(const char* json, MessageMap& messages) {
379
+ Reader reader;
380
+ MessageHandler handler;
381
+ StringStream ss(json);
382
+ if (reader.Parse(ss, handler))
383
+ messages.swap(handler.messages_); // Only change it if success.
384
+ else {
385
+ ParseErrorCode e = reader.GetParseErrorCode();
386
+ size_t o = reader.GetErrorOffset();
387
+ cout << "Error: " << GetParseError_En(e) << endl;;
388
+ cout << " at offset " << o << " near '" << string(json).substr(o, 10) << "...'" << endl;
389
+ }
390
+ }
391
+
392
+ int main() {
393
+ MessageMap messages;
394
+
395
+ const char* json1 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\" }";
396
+ cout << json1 << endl;
397
+ ParseMessages(json1, messages);
398
+
399
+ for (MessageMap::const_iterator itr = messages.begin(); itr != messages.end(); ++itr)
400
+ cout << itr->first << ": " << itr->second << endl;
401
+
402
+ cout << endl << "Parse a JSON with invalid schema." << endl;
403
+ const char* json2 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\", \"foo\" : {} }";
404
+ cout << json2 << endl;
405
+ ParseMessages(json2, messages);
406
+
407
+ return 0;
408
+ }
409
+ ~~~~~~~~~~
410
+
411
+ ~~~~~~~~~~
412
+ { "greeting" : "Hello!", "farewell" : "bye-bye!" }
413
+ farewell: bye-bye!
414
+ greeting: Hello!
415
+
416
+ Parse a JSON with invalid schema.
417
+ { "greeting" : "Hello!", "farewell" : "bye-bye!", "foo" : {} }
418
+ Error: Terminate parsing due to Handler error.
419
+ at offset 59 near '} }...'
420
+ ~~~~~~~~~~
421
+
422
+ The first JSON (`json1`) was successfully parsed into `MessageMap`. Since `MessageMap` is a `std::map`, the printing order are sorted by the key. This order is different from the JSON's order.
423
+
424
+ In the second JSON (`json2`), `foo`'s value is an empty object. As it is an object, `MessageHandler::StartObject()` will be called. However, at that moment `state_ = kExpectValue`, so that function returns `false` and cause the parsing process be terminated. The error code is `kParseErrorTermination`.
425
+
426
+ ## Filtering of JSON {#Filtering}
427
+
428
+ As mentioned earlier, `Writer` can handle the events published by `Reader`. `condense` example simply set a `Writer` as handler of a `Reader`, so it can remove all white-spaces in JSON. `pretty` example uses the same relationship, but replacing `Writer` by `PrettyWriter`. So `pretty` can be used to reformat a JSON with indentation and line feed.
429
+
430
+ Actually, we can add intermediate layer(s) to filter the contents of JSON via these SAX-style API. For example, `capitalize` example capitalize all strings in a JSON.
431
+
432
+ ~~~~~~~~~~cpp
433
+ #include "rapidjson/reader.h"
434
+ #include "rapidjson/writer.h"
435
+ #include "rapidjson/filereadstream.h"
436
+ #include "rapidjson/filewritestream.h"
437
+ #include "rapidjson/error/en.h"
438
+ #include <vector>
439
+ #include <cctype>
440
+
441
+ using namespace rapidjson;
442
+
443
+ template<typename OutputHandler>
444
+ struct CapitalizeFilter {
445
+ CapitalizeFilter(OutputHandler& out) : out_(out), buffer_() {
446
+ }
447
+
448
+ bool Null() { return out_.Null(); }
449
+ bool Bool(bool b) { return out_.Bool(b); }
450
+ bool Int(int i) { return out_.Int(i); }
451
+ bool Uint(unsigned u) { return out_.Uint(u); }
452
+ bool Int64(int64_t i) { return out_.Int64(i); }
453
+ bool Uint64(uint64_t u) { return out_.Uint64(u); }
454
+ bool Double(double d) { return out_.Double(d); }
455
+ bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); }
456
+ bool String(const char* str, SizeType length, bool) {
457
+ buffer_.clear();
458
+ for (SizeType i = 0; i < length; i++)
459
+ buffer_.push_back(std::toupper(str[i]));
460
+ return out_.String(&buffer_.front(), length, true); // true = output handler need to copy the string
461
+ }
462
+ bool StartObject() { return out_.StartObject(); }
463
+ bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); }
464
+ bool EndObject(SizeType memberCount) { return out_.EndObject(memberCount); }
465
+ bool StartArray() { return out_.StartArray(); }
466
+ bool EndArray(SizeType elementCount) { return out_.EndArray(elementCount); }
467
+
468
+ OutputHandler& out_;
469
+ std::vector<char> buffer_;
470
+ };
471
+
472
+ int main(int, char*[]) {
473
+ // Prepare JSON reader and input stream.
474
+ Reader reader;
475
+ char readBuffer[65536];
476
+ FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
477
+
478
+ // Prepare JSON writer and output stream.
479
+ char writeBuffer[65536];
480
+ FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
481
+ Writer<FileWriteStream> writer(os);
482
+
483
+ // JSON reader parse from the input stream and let writer generate the output.
484
+ CapitalizeFilter<Writer<FileWriteStream> > filter(writer);
485
+ if (!reader.Parse(is, filter)) {
486
+ fprintf(stderr, "\nError(%u): %s\n", (unsigned)reader.GetErrorOffset(), GetParseError_En(reader.GetParseErrorCode()));
487
+ return 1;
488
+ }
489
+
490
+ return 0;
491
+ }
492
+ ~~~~~~~~~~
493
+
494
+ Note that, it is incorrect to simply capitalize the JSON as a string. For example:
495
+ ~~~~~~~~~~
496
+ ["Hello\nWorld"]
497
+ ~~~~~~~~~~
498
+
499
+ Simply capitalizing the whole JSON would contain incorrect escape character:
500
+ ~~~~~~~~~~
501
+ ["HELLO\NWORLD"]
502
+ ~~~~~~~~~~
503
+
504
+ The correct result by `capitalize`:
505
+ ~~~~~~~~~~
506
+ ["HELLO\nWORLD"]
507
+ ~~~~~~~~~~
508
+
509
+ More complicated filters can be developed. However, since SAX-style API can only provide information about a single event at a time, user may need to book-keeping the contextual information (e.g. the path from root value, storage of other related values). Some processing may be easier to be implemented in DOM than SAX.