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,11 @@
1
+ <!-- HTML footer for doxygen 1.8.7-->
2
+ <!-- start footer part -->
3
+ <!--BEGIN GENERATE_TREEVIEW-->
4
+ <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
5
+ <ul>
6
+ $navpath
7
+ </ul>
8
+ </div>
9
+ <!--END GENERATE_TREEVIEW-->
10
+ </body>
11
+ </html>
@@ -0,0 +1,24 @@
1
+ <!-- HTML header for doxygen 1.8.7-->
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
6
+ <meta http-equiv="X-UA-Compatible" content="IE=9"/>
7
+ <meta name="generator" content="Doxygen $doxygenversion"/>
8
+ <!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
9
+ <!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
10
+ <link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
11
+ <script type="text/javascript" src="$relpath^jquery.js"></script>
12
+ <script type="text/javascript" src="$relpath^dynsections.js"></script>
13
+ $treeview
14
+ $search
15
+ $mathjax
16
+ <link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
17
+ $extrastylesheet
18
+ </head>
19
+ <body>
20
+ <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
21
+ <div id="topbanner"><a href="https://github.com/Tencent/rapidjson" title="RapidJSON GitHub"><i class="githublogo"></i></a></div>
22
+ $searchbox
23
+ <!--END TITLEAREA-->
24
+ <!-- end header part -->
@@ -0,0 +1,31 @@
1
+ ## NPM
2
+
3
+ # package.json {#package}
4
+
5
+ ~~~~~~~~~~js
6
+ {
7
+ ...
8
+ "dependencies": {
9
+ ...
10
+ "rapidjson": "git@github.com:Tencent/rapidjson.git"
11
+ },
12
+ ...
13
+ "gypfile": true
14
+ }
15
+ ~~~~~~~~~~
16
+
17
+ # binding.gyp {#binding}
18
+
19
+ ~~~~~~~~~~js
20
+ {
21
+ ...
22
+ 'targets': [
23
+ {
24
+ ...
25
+ 'include_dirs': [
26
+ '<!(node -e \'require("rapidjson")\')'
27
+ ]
28
+ }
29
+ ]
30
+ }
31
+ ~~~~~~~~~~
@@ -0,0 +1,26 @@
1
+ # Performance
2
+
3
+ There is a [native JSON benchmark collection] [1] which evaluates speed, memory usage and code size of various operations among 37 JSON libraries.
4
+
5
+ [1]: https://github.com/miloyip/nativejson-benchmark
6
+
7
+ The old performance article for RapidJSON 0.1 is provided [here](https://code.google.com/p/rapidjson/wiki/Performance).
8
+
9
+ Additionally, you may refer to the following third-party benchmarks.
10
+
11
+ ## Third-party benchmarks
12
+
13
+ * [Basic benchmarks for miscellaneous C++ JSON parsers and generators](https://github.com/mloskot/json_benchmark) by Mateusz Loskot (Jun 2013)
14
+ * [casablanca](https://casablanca.codeplex.com/)
15
+ * [json_spirit](https://github.com/cierelabs/json_spirit)
16
+ * [jsoncpp](http://jsoncpp.sourceforge.net/)
17
+ * [libjson](http://sourceforge.net/projects/libjson/)
18
+ * [rapidjson](https://github.com/Tencent/rapidjson/)
19
+ * [QJsonDocument](http://qt-project.org/doc/qt-5.0/qtcore/qjsondocument.html)
20
+
21
+ * [JSON Parser Benchmarking](http://chadaustin.me/2013/01/json-parser-benchmarking/) by Chad Austin (Jan 2013)
22
+ * [sajson](https://github.com/chadaustin/sajson)
23
+ * [rapidjson](https://github.com/Tencent/rapidjson/)
24
+ * [vjson](https://code.google.com/p/vjson/)
25
+ * [YAJL](http://lloyd.github.com/yajl/)
26
+ * [Jansson](http://www.digip.org/jansson/)
@@ -0,0 +1,26 @@
1
+ # 性能
2
+
3
+ 有一个 [native JSON benchmark collection][1] 项目,能评估 37 个 JSON 库在不同操作下的速度、內存用量及代码大小。
4
+
5
+ [1]: https://github.com/miloyip/nativejson-benchmark
6
+
7
+ RapidJSON 0.1 版本的性能测试文章位于 [这里](https://code.google.com/p/rapidjson/wiki/Performance).
8
+
9
+ 此外,你也可以参考以下这些第三方的评测。
10
+
11
+ ## 第三方评测
12
+
13
+ * [Basic benchmarks for miscellaneous C++ JSON parsers and generators](https://github.com/mloskot/json_benchmark) by Mateusz Loskot (Jun 2013)
14
+ * [casablanca](https://casablanca.codeplex.com/)
15
+ * [json_spirit](https://github.com/cierelabs/json_spirit)
16
+ * [jsoncpp](http://jsoncpp.sourceforge.net/)
17
+ * [libjson](http://sourceforge.net/projects/libjson/)
18
+ * [rapidjson](https://github.com/Tencent/rapidjson/)
19
+ * [QJsonDocument](http://qt-project.org/doc/qt-5.0/qtcore/qjsondocument.html)
20
+
21
+ * [JSON Parser Benchmarking](http://chadaustin.me/2013/01/json-parser-benchmarking/) by Chad Austin (Jan 2013)
22
+ * [sajson](https://github.com/chadaustin/sajson)
23
+ * [rapidjson](https://github.com/Tencent/rapidjson/)
24
+ * [vjson](https://code.google.com/p/vjson/)
25
+ * [YAJL](http://lloyd.github.com/yajl/)
26
+ * [Jansson](http://www.digip.org/jansson/)
@@ -0,0 +1,234 @@
1
+ # Pointer
2
+
3
+ (This feature was released in v1.1.0)
4
+
5
+ JSON Pointer is a standardized ([RFC6901]) way to select a value inside a JSON Document (DOM). This can be analogous to XPath for XML document. However, JSON Pointer is much simpler, and a single JSON Pointer only pointed to a single value.
6
+
7
+ Using RapidJSON's implementation of JSON Pointer can simplify some manipulations of the DOM.
8
+
9
+ [TOC]
10
+
11
+ # JSON Pointer {#JsonPointer}
12
+
13
+ A JSON Pointer is a list of zero-to-many tokens, each prefixed by `/`. Each token can be a string or a number. For example, given a JSON:
14
+ ~~~javascript
15
+ {
16
+ "foo" : ["bar", "baz"],
17
+ "pi" : 3.1416
18
+ }
19
+ ~~~
20
+
21
+ The following JSON Pointers resolve this JSON as:
22
+
23
+ 1. `"/foo"` → `[ "bar", "baz" ]`
24
+ 2. `"/foo/0"` → `"bar"`
25
+ 3. `"/foo/1"` → `"baz"`
26
+ 4. `"/pi"` → `3.1416`
27
+
28
+ Note that, an empty JSON Pointer `""` (zero token) resolves to the whole JSON.
29
+
30
+ # Basic Usage {#BasicUsage}
31
+
32
+ The following example code is self-explanatory.
33
+
34
+ ~~~cpp
35
+ #include "rapidjson/pointer.h"
36
+
37
+ // ...
38
+ Document d;
39
+
40
+ // Create DOM by Set()
41
+ Pointer("/project").Set(d, "RapidJSON");
42
+ Pointer("/stars").Set(d, 10);
43
+
44
+ // { "project" : "RapidJSON", "stars" : 10 }
45
+
46
+ // Access DOM by Get(). It return nullptr if the value does not exist.
47
+ if (Value* stars = Pointer("/stars").Get(d))
48
+ stars->SetInt(stars->GetInt() + 1);
49
+
50
+ // { "project" : "RapidJSON", "stars" : 11 }
51
+
52
+ // Set() and Create() automatically generate parents if not exist.
53
+ Pointer("/a/b/0").Create(d);
54
+
55
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] } }
56
+
57
+ // GetWithDefault() returns reference. And it deep clones the default value.
58
+ Value& hello = Pointer("/hello").GetWithDefault(d, "world");
59
+
60
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] }, "hello" : "world" }
61
+
62
+ // Swap() is similar to Set()
63
+ Value x("C++");
64
+ Pointer("/hello").Swap(d, x);
65
+
66
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] }, "hello" : "C++" }
67
+ // x becomes "world"
68
+
69
+ // Erase a member or element, return true if the value exists
70
+ bool success = Pointer("/a").Erase(d);
71
+ assert(success);
72
+
73
+ // { "project" : "RapidJSON", "stars" : 10 }
74
+ ~~~
75
+
76
+ # Helper Functions {#HelperFunctions}
77
+
78
+ Since object-oriented calling convention may be non-intuitive, RapidJSON also provides helper functions, which just wrap the member functions with free-functions.
79
+
80
+ The following example does exactly the same as the above one.
81
+
82
+ ~~~cpp
83
+ Document d;
84
+
85
+ SetValueByPointer(d, "/project", "RapidJSON");
86
+ SetValueByPointer(d, "/stars", 10);
87
+
88
+ if (Value* stars = GetValueByPointer(d, "/stars"))
89
+ stars->SetInt(stars->GetInt() + 1);
90
+
91
+ CreateValueByPointer(d, "/a/b/0");
92
+
93
+ Value& hello = GetValueByPointerWithDefault(d, "/hello", "world");
94
+
95
+ Value x("C++");
96
+ SwapValueByPointer(d, "/hello", x);
97
+
98
+ bool success = EraseValueByPointer(d, "/a");
99
+ assert(success);
100
+ ~~~
101
+
102
+ The conventions are shown here for comparison:
103
+
104
+ 1. `Pointer(source).<Method>(root, ...)`
105
+ 2. `<Method>ValueByPointer(root, Pointer(source), ...)`
106
+ 3. `<Method>ValueByPointer(root, source, ...)`
107
+
108
+ # Resolving Pointer {#ResolvingPointer}
109
+
110
+ `Pointer::Get()` or `GetValueByPointer()` function does not modify the DOM. If the tokens cannot match a value in the DOM, it returns `nullptr`. User can use this to check whether a value exists.
111
+
112
+ Note that, numerical tokens can represent an array index or member name. The resolving process will match the values according to the types of value.
113
+
114
+ ~~~javascript
115
+ {
116
+ "0" : 123,
117
+ "1" : [456]
118
+ }
119
+ ~~~
120
+
121
+ 1. `"/0"` → `123`
122
+ 2. `"/1/0"` → `456`
123
+
124
+ The token `"0"` is treated as member name in the first pointer. It is treated as an array index in the second pointer.
125
+
126
+ The other functions, including `Create()`, `GetWithDefault()`, `Set()` and `Swap()`, will change the DOM. These functions will always succeed. They will create the parent values if they do not exist. If the parent values do not match the tokens, they will also be forced to change their type. Changing the type also mean fully removal of that DOM subtree.
127
+
128
+ Parsing the above JSON into `d`,
129
+
130
+ ~~~cpp
131
+ SetValueByPointer(d, "1/a", 789); // { "0" : 123, "1" : { "a" : 789 } }
132
+ ~~~
133
+
134
+ ## Resolving Minus Sign Token
135
+
136
+ Besides, [RFC6901] defines a special token `-` (single minus sign), which represents the pass-the-end element of an array. `Get()` only treats this token as a member name '"-"'. Yet the other functions can resolve this for array, equivalent to calling `Value::PushBack()` to the array.
137
+
138
+ ~~~cpp
139
+ Document d;
140
+ d.Parse("{\"foo\":[123]}");
141
+ SetValueByPointer(d, "/foo/-", 456); // { "foo" : [123, 456] }
142
+ SetValueByPointer(d, "/-", 789); // { "foo" : [123, 456], "-" : 789 }
143
+ ~~~
144
+
145
+ ## Resolving Document and Value
146
+
147
+ When using `p.Get(root)` or `GetValueByPointer(root, p)`, `root` is a (const) `Value&`. That means, it can be a subtree of the DOM.
148
+
149
+ The other functions have two groups of signature. One group uses `Document& document` as parameter, another one uses `Value& root`. The first group uses `document.GetAllocator()` for creating values. And the second group needs user to supply an allocator, like the functions in DOM.
150
+
151
+ All examples above do not require an allocator parameter, because the first parameter is a `Document&`. But if you want to resolve a pointer to a subtree, you need to supply the allocator as in the following example:
152
+
153
+ ~~~cpp
154
+ class Person {
155
+ public:
156
+ Person() {
157
+ document_ = new Document();
158
+ // CreateValueByPointer() here no need allocator
159
+ SetLocation(CreateValueByPointer(*document_, "/residence"), ...);
160
+ SetLocation(CreateValueByPointer(*document_, "/office"), ...);
161
+ };
162
+
163
+ private:
164
+ void SetLocation(Value& location, const char* country, const char* addresses[2]) {
165
+ Value::Allocator& a = document_->GetAllocator();
166
+ // SetValueByPointer() here need allocator
167
+ SetValueByPointer(location, "/country", country, a);
168
+ SetValueByPointer(location, "/address/0", address[0], a);
169
+ SetValueByPointer(location, "/address/1", address[1], a);
170
+ }
171
+
172
+ // ...
173
+
174
+ Document* document_;
175
+ };
176
+ ~~~
177
+
178
+ `Erase()` or `EraseValueByPointer()` does not need allocator. And they return `true` if the value is erased successfully.
179
+
180
+ # Error Handling {#ErrorHandling}
181
+
182
+ A `Pointer` parses a source string in its constructor. If there is parsing error, `Pointer::IsValid()` returns `false`. And you can use `Pointer::GetParseErrorCode()` and `GetParseErrorOffset()` to retrieve the error information.
183
+
184
+ Note that, all resolving functions assumes valid pointer. Resolving with an invalid pointer causes assertion failure.
185
+
186
+ # URI Fragment Representation {#URIFragment}
187
+
188
+ In addition to the string representation of JSON pointer that we are using till now, [RFC6901] also defines the URI fragment representation of JSON pointer. URI fragment is specified in [RFC3986] "Uniform Resource Identifier (URI): Generic Syntax".
189
+
190
+ The main differences are that a the URI fragment always has a `#` (pound sign) in the beginning, and some characters are encoded by percent-encoding in UTF-8 sequence. For example, the following table shows different C/C++ string literals of different representations.
191
+
192
+ String Representation | URI Fragment Representation | Pointer Tokens (UTF-8)
193
+ ----------------------|-----------------------------|------------------------
194
+ `"/foo/0"` | `"#/foo/0"` | `{"foo", 0}`
195
+ `"/a~1b"` | `"#/a~1b"` | `{"a/b"}`
196
+ `"/m~0n"` | `"#/m~0n"` | `{"m~n"}`
197
+ `"/ "` | `"#/%20"` | `{" "}`
198
+ `"/\0"` | `"#/%00"` | `{"\0"}`
199
+ `"/€"` | `"#/%E2%82%AC"` | `{"€"}`
200
+
201
+ RapidJSON fully support URI fragment representation. It automatically detects the pound sign during parsing.
202
+
203
+ # Stringify
204
+
205
+ You may also stringify a `Pointer` to a string or other output streams. This can be done by:
206
+
207
+ ~~~
208
+ Pointer p(...);
209
+ StringBuffer sb;
210
+ p.Stringify(sb);
211
+ std::cout << sb.GetString() << std::endl;
212
+ ~~~
213
+
214
+ It can also stringify to URI fragment representation by `StringifyUriFragment()`.
215
+
216
+ # User-Supplied Tokens {#UserSuppliedTokens}
217
+
218
+ If a pointer will be resolved multiple times, it should be constructed once, and then apply it to different DOMs or in different times. This reduce time and memory allocation for constructing `Pointer` multiple times.
219
+
220
+ We can go one step further, to completely eliminate the parsing process and dynamic memory allocation, we can establish the token array directly:
221
+
222
+ ~~~cpp
223
+ #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
224
+ #define INDEX(i) { #i, sizeof(#i) - 1, i }
225
+
226
+ static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) };
227
+ static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0]));
228
+ // Equivalent to static const Pointer p("/foo/123");
229
+ ~~~
230
+
231
+ This may be useful for memory constrained systems.
232
+
233
+ [RFC3986]: https://tools.ietf.org/html/rfc3986
234
+ [RFC6901]: https://tools.ietf.org/html/rfc6901
@@ -0,0 +1,234 @@
1
+ # Pointer
2
+
3
+ (本功能于 v1.1.0 发布)
4
+
5
+ JSON Pointer 是一个标准化([RFC6901])的方式去选取一个 JSON Document(DOM)中的值。这类似于 XML 的 XPath。然而,JSON Pointer 简单得多,而且每个 JSON Pointer 仅指向单个值。
6
+
7
+ 使用 RapidJSON 的 JSON Pointer 实现能简化一些 DOM 的操作。
8
+
9
+ [TOC]
10
+
11
+ # JSON Pointer {#JsonPointer}
12
+
13
+ 一个 JSON Pointer 由一串(零至多个)token 所组成,每个 token 都有 `/` 前缀。每个 token 可以是一个字符串或数字。例如,给定一个 JSON:
14
+ ~~~javascript
15
+ {
16
+ "foo" : ["bar", "baz"],
17
+ "pi" : 3.1416
18
+ }
19
+ ~~~
20
+
21
+ 以下的 JSON Pointer 解析为:
22
+
23
+ 1. `"/foo"` → `[ "bar", "baz" ]`
24
+ 2. `"/foo/0"` → `"bar"`
25
+ 3. `"/foo/1"` → `"baz"`
26
+ 4. `"/pi"` → `3.1416`
27
+
28
+ 要注意,一个空 JSON Pointer `""` (零个 token)解析为整个 JSON。
29
+
30
+ # 基本使用方法 {#BasicUsage}
31
+
32
+ 以下的代码范例不解自明。
33
+
34
+ ~~~cpp
35
+ #include "rapidjson/pointer.h"
36
+
37
+ // ...
38
+ Document d;
39
+
40
+ // 使用 Set() 创建 DOM
41
+ Pointer("/project").Set(d, "RapidJSON");
42
+ Pointer("/stars").Set(d, 10);
43
+
44
+ // { "project" : "RapidJSON", "stars" : 10 }
45
+
46
+ // 使用 Get() 访问 DOM。若该值不存在则返回 nullptr。
47
+ if (Value* stars = Pointer("/stars").Get(d))
48
+ stars->SetInt(stars->GetInt() + 1);
49
+
50
+ // { "project" : "RapidJSON", "stars" : 11 }
51
+
52
+ // Set() 和 Create() 自动生成父值(如果它们不存在)。
53
+ Pointer("/a/b/0").Create(d);
54
+
55
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] } }
56
+
57
+ // GetWithDefault() 返回引用。若该值不存在则会深拷贝缺省值。
58
+ Value& hello = Pointer("/hello").GetWithDefault(d, "world");
59
+
60
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] }, "hello" : "world" }
61
+
62
+ // Swap() 和 Set() 相似
63
+ Value x("C++");
64
+ Pointer("/hello").Swap(d, x);
65
+
66
+ // { "project" : "RapidJSON", "stars" : 11, "a" : { "b" : [ null ] }, "hello" : "C++" }
67
+ // x 变成 "world"
68
+
69
+ // 删去一个成员或元素,若值存在返回 true
70
+ bool success = Pointer("/a").Erase(d);
71
+ assert(success);
72
+
73
+ // { "project" : "RapidJSON", "stars" : 10 }
74
+ ~~~
75
+
76
+ # 辅助函数 {#HelperFunctions}
77
+
78
+ 由于面向对象的调用习惯可能不符直觉,RapidJSON 也提供了一些辅助函数,它们把成员函数包装成自由函数。
79
+
80
+ 以下的例子与上面例子所做的事情完全相同。
81
+
82
+ ~~~cpp
83
+ Document d;
84
+
85
+ SetValueByPointer(d, "/project", "RapidJSON");
86
+ SetValueByPointer(d, "/stars", 10);
87
+
88
+ if (Value* stars = GetValueByPointer(d, "/stars"))
89
+ stars->SetInt(stars->GetInt() + 1);
90
+
91
+ CreateValueByPointer(d, "/a/b/0");
92
+
93
+ Value& hello = GetValueByPointerWithDefault(d, "/hello", "world");
94
+
95
+ Value x("C++");
96
+ SwapValueByPointer(d, "/hello", x);
97
+
98
+ bool success = EraseValueByPointer(d, "/a");
99
+ assert(success);
100
+ ~~~
101
+
102
+ 以下对比 3 种调用方式:
103
+
104
+ 1. `Pointer(source).<Method>(root, ...)`
105
+ 2. `<Method>ValueByPointer(root, Pointer(source), ...)`
106
+ 3. `<Method>ValueByPointer(root, source, ...)`
107
+
108
+ # 解析 Pointer {#ResolvingPointer}
109
+
110
+ `Pointer::Get()` 或 `GetValueByPointer()` 函数并不修改 DOM。若那些 token 不能匹配 DOM 里的值,这些函数便返回 `nullptr`。使用者可利用这个方法来检查一个值是否存在。
111
+
112
+ 注意,数值 token 可表示数组索引或成员名字。解析过程中会按值的类型来匹配。
113
+
114
+ ~~~javascript
115
+ {
116
+ "0" : 123,
117
+ "1" : [456]
118
+ }
119
+ ~~~
120
+
121
+ 1. `"/0"` → `123`
122
+ 2. `"/1/0"` → `456`
123
+
124
+ Token `"0"` 在第一个 pointer 中被当作成员名字。它在第二个 pointer 中被当作成数组索引。
125
+
126
+ 其他函数会改变 DOM,包括 `Create()`、`GetWithDefault()`、`Set()`、`Swap()`。这些函数总是成功的。若一些父值不存在,就会创建它们。若父值类型不匹配 token,也会强行改变其类型。改变类型也意味着完全移除其 DOM 子树的内容。
127
+
128
+ 例如,把上面的 JSON 解译至 `d` 之后,
129
+
130
+ ~~~cpp
131
+ SetValueByPointer(d, "1/a", 789); // { "0" : 123, "1" : { "a" : 789 } }
132
+ ~~~
133
+
134
+ ## 解析负号 token
135
+
136
+ 另外,[RFC6901] 定义了一个特殊 token `-` (单个负号),用于表示数组最后元素的下一个元素。 `Get()` 只会把此 token 当作成员名字 '"-"'。而其他函数则会以此解析数组,等同于对数组调用 `Value::PushBack()` 。
137
+
138
+ ~~~cpp
139
+ Document d;
140
+ d.Parse("{\"foo\":[123]}");
141
+ SetValueByPointer(d, "/foo/-", 456); // { "foo" : [123, 456] }
142
+ SetValueByPointer(d, "/-", 789); // { "foo" : [123, 456], "-" : 789 }
143
+ ~~~
144
+
145
+ ## 解析 Document 及 Value
146
+
147
+ 当使用 `p.Get(root)` 或 `GetValueByPointer(root, p)`,`root` 是一个(常数) `Value&`。这意味着,它也可以是 DOM 里的一个子树。
148
+
149
+ 其他函数有两组签名。一组使用 `Document& document` 作为参数,另一组使用 `Value& root`。第一组使用 `document.GetAllocator()` 去创建值,而第二组则需要使用者提供一个 allocator,如同 DOM 里的函数。
150
+
151
+ 以上例子都不需要 allocator 参数,因为它的第一个参数是 `Document&`。但如果你需要对一个子树进行解析,就需要如下面的例子般提供 allocator:
152
+
153
+ ~~~cpp
154
+ class Person {
155
+ public:
156
+ Person() {
157
+ document_ = new Document();
158
+ // CreateValueByPointer() here no need allocator
159
+ SetLocation(CreateValueByPointer(*document_, "/residence"), ...);
160
+ SetLocation(CreateValueByPointer(*document_, "/office"), ...);
161
+ };
162
+
163
+ private:
164
+ void SetLocation(Value& location, const char* country, const char* addresses[2]) {
165
+ Value::Allocator& a = document_->GetAllocator();
166
+ // SetValueByPointer() here need allocator
167
+ SetValueByPointer(location, "/country", country, a);
168
+ SetValueByPointer(location, "/address/0", address[0], a);
169
+ SetValueByPointer(location, "/address/1", address[1], a);
170
+ }
171
+
172
+ // ...
173
+
174
+ Document* document_;
175
+ };
176
+ ~~~
177
+
178
+ `Erase()` 或 `EraseValueByPointer()` 不需要 allocator。而且它们成功删除值之后会返回 `true`。
179
+
180
+ # 错误处理 {#ErrorHandling}
181
+
182
+ `Pointer` 在其建构函数里会解译源字符串。若有解析错误,`Pointer::IsValid()` 返回 `false`。你可使用 `Pointer::GetParseErrorCode()` 和 `GetParseErrorOffset()` 去获取错信息。
183
+
184
+ 要注意的是,所有解析函数都假设 pointer 是合法的。对一个非法 pointer 解析会做成断言失败。
185
+
186
+ # URI 片段表示方式 {#URIFragment}
187
+
188
+ 除了我们一直在使用的字符串方式表示 JSON pointer,[RFC6901] 也定义了一个 JSON Pointer 的 URI 片段(fragment)表示方式。URI 片段是定义于 [RFC3986] "Uniform Resource Identifier (URI): Generic Syntax"。
189
+
190
+ URI 片段的主要分别是必然以 `#` (pound sign)开头,而一些字符也会以百分比编码成 UTF-8 序列。例如,以下的表展示了不同表示法下的 C/C++ 字符串常数。
191
+
192
+ 字符串表示方式 | URI 片段表示方式 | Pointer Tokens (UTF-8)
193
+ ----------------------|-----------------------------|------------------------
194
+ `"/foo/0"` | `"#/foo/0"` | `{"foo", 0}`
195
+ `"/a~1b"` | `"#/a~1b"` | `{"a/b"}`
196
+ `"/m~0n"` | `"#/m~0n"` | `{"m~n"}`
197
+ `"/ "` | `"#/%20"` | `{" "}`
198
+ `"/\0"` | `"#/%00"` | `{"\0"}`
199
+ `"/€"` | `"#/%E2%82%AC"` | `{"€"}`
200
+
201
+ RapidJSON 完全支持 URI 片段表示方式。它在解译时会自动检测 `#` 号。
202
+
203
+ # 字符串化
204
+
205
+ 你也可以把一个 `Pointer` 字符串化,储存于字符串或其他输出流。例如:
206
+
207
+ ~~~
208
+ Pointer p(...);
209
+ StringBuffer sb;
210
+ p.Stringify(sb);
211
+ std::cout << sb.GetString() << std::endl;
212
+ ~~~
213
+
214
+ 使用 `StringifyUriFragment()` 可以把 pointer 字符串化为 URI 片段表示法。
215
+
216
+ # 使用者提供的 tokens {#UserSuppliedTokens}
217
+
218
+ 若一个 pointer 会用于多次解析,它应该只被创建一次,然后再施于不同的 DOM ,或在不同时间做解析。这样可以避免多次创键 `Pointer`,节省时间和内存分配。
219
+
220
+ 我们甚至可以再更进一步,完全消去解析过程及动态内存分配。我们可以直接生成 token 数组:
221
+
222
+ ~~~cpp
223
+ #define NAME(s) { s, sizeof(s) / sizeof(s[0]) - 1, kPointerInvalidIndex }
224
+ #define INDEX(i) { #i, sizeof(#i) - 1, i }
225
+
226
+ static const Pointer::Token kTokens[] = { NAME("foo"), INDEX(123) };
227
+ static const Pointer p(kTokens, sizeof(kTokens) / sizeof(kTokens[0]));
228
+ // Equivalent to static const Pointer p("/foo/123");
229
+ ~~~
230
+
231
+ 这种做法可能适合内存受限的系统。
232
+
233
+ [RFC3986]: https://tools.ietf.org/html/rfc3986
234
+ [RFC6901]: https://tools.ietf.org/html/rfc6901