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,223 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #include "rapidjson.h"
16
+
17
+ #ifndef RAPIDJSON_STREAM_H_
18
+ #define RAPIDJSON_STREAM_H_
19
+
20
+ #include "encodings.h"
21
+
22
+ RAPIDJSON_NAMESPACE_BEGIN
23
+
24
+ ///////////////////////////////////////////////////////////////////////////////
25
+ // Stream
26
+
27
+ /*! \class rapidjson::Stream
28
+ \brief Concept for reading and writing characters.
29
+
30
+ For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd().
31
+
32
+ For write-only stream, only need to implement Put() and Flush().
33
+
34
+ \code
35
+ concept Stream {
36
+ typename Ch; //!< Character type of the stream.
37
+
38
+ //! Read the current character from stream without moving the read cursor.
39
+ Ch Peek() const;
40
+
41
+ //! Read the current character from stream and moving the read cursor to next character.
42
+ Ch Take();
43
+
44
+ //! Get the current read cursor.
45
+ //! \return Number of characters read from start.
46
+ size_t Tell();
47
+
48
+ //! Begin writing operation at the current read pointer.
49
+ //! \return The begin writer pointer.
50
+ Ch* PutBegin();
51
+
52
+ //! Write a character.
53
+ void Put(Ch c);
54
+
55
+ //! Flush the buffer.
56
+ void Flush();
57
+
58
+ //! End the writing operation.
59
+ //! \param begin The begin write pointer returned by PutBegin().
60
+ //! \return Number of characters written.
61
+ size_t PutEnd(Ch* begin);
62
+ }
63
+ \endcode
64
+ */
65
+
66
+ //! Provides additional information for stream.
67
+ /*!
68
+ By using traits pattern, this type provides a default configuration for stream.
69
+ For custom stream, this type can be specialized for other configuration.
70
+ See TEST(Reader, CustomStringStream) in readertest.cpp for example.
71
+ */
72
+ template<typename Stream>
73
+ struct StreamTraits {
74
+ //! Whether to make local copy of stream for optimization during parsing.
75
+ /*!
76
+ By default, for safety, streams do not use local copy optimization.
77
+ Stream that can be copied fast should specialize this, like StreamTraits<StringStream>.
78
+ */
79
+ enum { copyOptimization = 0 };
80
+ };
81
+
82
+ //! Reserve n characters for writing to a stream.
83
+ template<typename Stream>
84
+ inline void PutReserve(Stream& stream, size_t count) {
85
+ (void)stream;
86
+ (void)count;
87
+ }
88
+
89
+ //! Write character to a stream, presuming buffer is reserved.
90
+ template<typename Stream>
91
+ inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
92
+ stream.Put(c);
93
+ }
94
+
95
+ //! Put N copies of a character to a stream.
96
+ template<typename Stream, typename Ch>
97
+ inline void PutN(Stream& stream, Ch c, size_t n) {
98
+ PutReserve(stream, n);
99
+ for (size_t i = 0; i < n; i++)
100
+ PutUnsafe(stream, c);
101
+ }
102
+
103
+ ///////////////////////////////////////////////////////////////////////////////
104
+ // GenericStreamWrapper
105
+
106
+ //! A Stream Wrapper
107
+ /*! \tThis string stream is a wrapper for any stream by just forwarding any
108
+ \treceived message to the origin stream.
109
+ \note implements Stream concept
110
+ */
111
+
112
+ #if defined(_MSC_VER) && _MSC_VER <= 1800
113
+ RAPIDJSON_DIAG_PUSH
114
+ RAPIDJSON_DIAG_OFF(4702) // unreachable code
115
+ RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
116
+ #endif
117
+
118
+ template <typename InputStream, typename Encoding = UTF8<> >
119
+ class GenericStreamWrapper {
120
+ public:
121
+ typedef typename Encoding::Ch Ch;
122
+ GenericStreamWrapper(InputStream& is): is_(is) {}
123
+
124
+ Ch Peek() const { return is_.Peek(); }
125
+ Ch Take() { return is_.Take(); }
126
+ size_t Tell() { return is_.Tell(); }
127
+ Ch* PutBegin() { return is_.PutBegin(); }
128
+ void Put(Ch ch) { is_.Put(ch); }
129
+ void Flush() { is_.Flush(); }
130
+ size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); }
131
+
132
+ // wrapper for MemoryStream
133
+ const Ch* Peek4() const { return is_.Peek4(); }
134
+
135
+ // wrapper for AutoUTFInputStream
136
+ UTFType GetType() const { return is_.GetType(); }
137
+ bool HasBOM() const { return is_.HasBOM(); }
138
+
139
+ protected:
140
+ InputStream& is_;
141
+ };
142
+
143
+ #if defined(_MSC_VER) && _MSC_VER <= 1800
144
+ RAPIDJSON_DIAG_POP
145
+ #endif
146
+
147
+ ///////////////////////////////////////////////////////////////////////////////
148
+ // StringStream
149
+
150
+ //! Read-only string stream.
151
+ /*! \note implements Stream concept
152
+ */
153
+ template <typename Encoding>
154
+ struct GenericStringStream {
155
+ typedef typename Encoding::Ch Ch;
156
+
157
+ GenericStringStream(const Ch *src) : src_(src), head_(src) {}
158
+
159
+ Ch Peek() const { return *src_; }
160
+ Ch Take() { return *src_++; }
161
+ size_t Tell() const { return static_cast<size_t>(src_ - head_); }
162
+
163
+ Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
164
+ void Put(Ch) { RAPIDJSON_ASSERT(false); }
165
+ void Flush() { RAPIDJSON_ASSERT(false); }
166
+ size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
167
+
168
+ const Ch* src_; //!< Current read position.
169
+ const Ch* head_; //!< Original head of the string.
170
+ };
171
+
172
+ template <typename Encoding>
173
+ struct StreamTraits<GenericStringStream<Encoding> > {
174
+ enum { copyOptimization = 1 };
175
+ };
176
+
177
+ //! String stream with UTF8 encoding.
178
+ typedef GenericStringStream<UTF8<> > StringStream;
179
+
180
+ ///////////////////////////////////////////////////////////////////////////////
181
+ // InsituStringStream
182
+
183
+ //! A read-write string stream.
184
+ /*! This string stream is particularly designed for in-situ parsing.
185
+ \note implements Stream concept
186
+ */
187
+ template <typename Encoding>
188
+ struct GenericInsituStringStream {
189
+ typedef typename Encoding::Ch Ch;
190
+
191
+ GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {}
192
+
193
+ // Read
194
+ Ch Peek() { return *src_; }
195
+ Ch Take() { return *src_++; }
196
+ size_t Tell() { return static_cast<size_t>(src_ - head_); }
197
+
198
+ // Write
199
+ void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
200
+
201
+ Ch* PutBegin() { return dst_ = src_; }
202
+ size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
203
+ void Flush() {}
204
+
205
+ Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
206
+ void Pop(size_t count) { dst_ -= count; }
207
+
208
+ Ch* src_;
209
+ Ch* dst_;
210
+ Ch* head_;
211
+ };
212
+
213
+ template <typename Encoding>
214
+ struct StreamTraits<GenericInsituStringStream<Encoding> > {
215
+ enum { copyOptimization = 1 };
216
+ };
217
+
218
+ //! Insitu string stream with UTF8 encoding.
219
+ typedef GenericInsituStringStream<UTF8<> > InsituStringStream;
220
+
221
+ RAPIDJSON_NAMESPACE_END
222
+
223
+ #endif // RAPIDJSON_STREAM_H_
@@ -0,0 +1,121 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #ifndef RAPIDJSON_STRINGBUFFER_H_
16
+ #define RAPIDJSON_STRINGBUFFER_H_
17
+
18
+ #include "stream.h"
19
+ #include "internal/stack.h"
20
+
21
+ #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
22
+ #include <utility> // std::move
23
+ #endif
24
+
25
+ #include "internal/stack.h"
26
+
27
+ #if defined(__clang__)
28
+ RAPIDJSON_DIAG_PUSH
29
+ RAPIDJSON_DIAG_OFF(c++98-compat)
30
+ #endif
31
+
32
+ RAPIDJSON_NAMESPACE_BEGIN
33
+
34
+ //! Represents an in-memory output stream.
35
+ /*!
36
+ \tparam Encoding Encoding of the stream.
37
+ \tparam Allocator type for allocating memory buffer.
38
+ \note implements Stream concept
39
+ */
40
+ template <typename Encoding, typename Allocator = CrtAllocator>
41
+ class GenericStringBuffer {
42
+ public:
43
+ typedef typename Encoding::Ch Ch;
44
+
45
+ GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
46
+
47
+ #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
48
+ GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {}
49
+ GenericStringBuffer& operator=(GenericStringBuffer&& rhs) {
50
+ if (&rhs != this)
51
+ stack_ = std::move(rhs.stack_);
52
+ return *this;
53
+ }
54
+ #endif
55
+
56
+ void Put(Ch c) { *stack_.template Push<Ch>() = c; }
57
+ void PutUnsafe(Ch c) { *stack_.template PushUnsafe<Ch>() = c; }
58
+ void Flush() {}
59
+
60
+ void Clear() { stack_.Clear(); }
61
+ void ShrinkToFit() {
62
+ // Push and pop a null terminator. This is safe.
63
+ *stack_.template Push<Ch>() = '\0';
64
+ stack_.ShrinkToFit();
65
+ stack_.template Pop<Ch>(1);
66
+ }
67
+
68
+ void Reserve(size_t count) { stack_.template Reserve<Ch>(count); }
69
+ Ch* Push(size_t count) { return stack_.template Push<Ch>(count); }
70
+ Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe<Ch>(count); }
71
+ void Pop(size_t count) { stack_.template Pop<Ch>(count); }
72
+
73
+ const Ch* GetString() const {
74
+ // Push and pop a null terminator. This is safe.
75
+ *stack_.template Push<Ch>() = '\0';
76
+ stack_.template Pop<Ch>(1);
77
+
78
+ return stack_.template Bottom<Ch>();
79
+ }
80
+
81
+ //! Get the size of string in bytes in the string buffer.
82
+ size_t GetSize() const { return stack_.GetSize(); }
83
+
84
+ //! Get the length of string in Ch in the string buffer.
85
+ size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); }
86
+
87
+ static const size_t kDefaultCapacity = 256;
88
+ mutable internal::Stack<Allocator> stack_;
89
+
90
+ private:
91
+ // Prohibit copy constructor & assignment operator.
92
+ GenericStringBuffer(const GenericStringBuffer&);
93
+ GenericStringBuffer& operator=(const GenericStringBuffer&);
94
+ };
95
+
96
+ //! String buffer with UTF8 encoding
97
+ typedef GenericStringBuffer<UTF8<> > StringBuffer;
98
+
99
+ template<typename Encoding, typename Allocator>
100
+ inline void PutReserve(GenericStringBuffer<Encoding, Allocator>& stream, size_t count) {
101
+ stream.Reserve(count);
102
+ }
103
+
104
+ template<typename Encoding, typename Allocator>
105
+ inline void PutUnsafe(GenericStringBuffer<Encoding, Allocator>& stream, typename Encoding::Ch c) {
106
+ stream.PutUnsafe(c);
107
+ }
108
+
109
+ //! Implement specialized version of PutN() with memset() for better performance.
110
+ template<>
111
+ inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
112
+ std::memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
113
+ }
114
+
115
+ RAPIDJSON_NAMESPACE_END
116
+
117
+ #if defined(__clang__)
118
+ RAPIDJSON_DIAG_POP
119
+ #endif
120
+
121
+ #endif // RAPIDJSON_STRINGBUFFER_H_
@@ -0,0 +1,716 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #ifndef RAPIDJSON_WRITER_H_
16
+ #define RAPIDJSON_WRITER_H_
17
+
18
+ #include "stream.h"
19
+ #include "internal/meta.h"
20
+ #include "internal/stack.h"
21
+ #include "internal/strfunc.h"
22
+ #include "internal/dtoa.h"
23
+ #include "internal/itoa.h"
24
+ #include "stringbuffer.h"
25
+ #include <new> // placement new
26
+
27
+ #if defined(RAPIDJSON_SIMD) && defined(_MSC_VER)
28
+ #include <intrin.h>
29
+ #pragma intrinsic(_BitScanForward)
30
+ #endif
31
+ #ifdef RAPIDJSON_SSE42
32
+ #include <nmmintrin.h>
33
+ #elif defined(RAPIDJSON_SSE2)
34
+ #include <emmintrin.h>
35
+ #elif defined(RAPIDJSON_NEON)
36
+ #include <arm_neon.h>
37
+ #endif
38
+
39
+ #ifdef _MSC_VER
40
+ RAPIDJSON_DIAG_PUSH
41
+ RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
42
+ #endif
43
+
44
+ #ifdef __clang__
45
+ RAPIDJSON_DIAG_PUSH
46
+ RAPIDJSON_DIAG_OFF(padded)
47
+ RAPIDJSON_DIAG_OFF(unreachable-code)
48
+ RAPIDJSON_DIAG_OFF(c++98-compat)
49
+ #endif
50
+
51
+ RAPIDJSON_NAMESPACE_BEGIN
52
+
53
+ ///////////////////////////////////////////////////////////////////////////////
54
+ // WriteFlag
55
+
56
+ /*! \def RAPIDJSON_WRITE_DEFAULT_FLAGS
57
+ \ingroup RAPIDJSON_CONFIG
58
+ \brief User-defined kWriteDefaultFlags definition.
59
+
60
+ User can define this as any \c WriteFlag combinations.
61
+ */
62
+ #ifndef RAPIDJSON_WRITE_DEFAULT_FLAGS
63
+ #define RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNoFlags
64
+ #endif
65
+
66
+ //! Combination of writeFlags
67
+ enum WriteFlag {
68
+ kWriteNoFlags = 0, //!< No flags are set.
69
+ kWriteValidateEncodingFlag = 1, //!< Validate encoding of JSON strings.
70
+ kWriteNanAndInfFlag = 2, //!< Allow writing of Infinity, -Infinity and NaN.
71
+ kWriteDefaultFlags = RAPIDJSON_WRITE_DEFAULT_FLAGS //!< Default write flags. Can be customized by defining RAPIDJSON_WRITE_DEFAULT_FLAGS
72
+ };
73
+
74
+ //! JSON writer
75
+ /*! Writer implements the concept Handler.
76
+ It generates JSON text by events to an output os.
77
+
78
+ User may programmatically calls the functions of a writer to generate JSON text.
79
+
80
+ On the other side, a writer can also be passed to objects that generates events,
81
+
82
+ for example Reader::Parse() and Document::Accept().
83
+
84
+ \tparam OutputStream Type of output stream.
85
+ \tparam SourceEncoding Encoding of source string.
86
+ \tparam TargetEncoding Encoding of output stream.
87
+ \tparam StackAllocator Type of allocator for allocating memory of stack.
88
+ \note implements Handler concept
89
+ */
90
+ template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
91
+ class Writer {
92
+ public:
93
+ typedef typename SourceEncoding::Ch Ch;
94
+
95
+ static const int kDefaultMaxDecimalPlaces = 324;
96
+
97
+ //! Constructor
98
+ /*! \param os Output stream.
99
+ \param stackAllocator User supplied allocator. If it is null, it will create a private one.
100
+ \param levelDepth Initial capacity of stack.
101
+ */
102
+ explicit
103
+ Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = kDefaultLevelDepth) :
104
+ os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
105
+
106
+ explicit
107
+ Writer(StackAllocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
108
+ os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
109
+
110
+ #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
111
+ Writer(Writer&& rhs) :
112
+ os_(rhs.os_), level_stack_(std::move(rhs.level_stack_)), maxDecimalPlaces_(rhs.maxDecimalPlaces_), hasRoot_(rhs.hasRoot_) {
113
+ rhs.os_ = 0;
114
+ }
115
+ #endif
116
+
117
+ //! Reset the writer with a new stream.
118
+ /*!
119
+ This function reset the writer with a new stream and default settings,
120
+ in order to make a Writer object reusable for output multiple JSONs.
121
+
122
+ \param os New output stream.
123
+ \code
124
+ Writer<OutputStream> writer(os1);
125
+ writer.StartObject();
126
+ // ...
127
+ writer.EndObject();
128
+
129
+ writer.Reset(os2);
130
+ writer.StartObject();
131
+ // ...
132
+ writer.EndObject();
133
+ \endcode
134
+ */
135
+ void Reset(OutputStream& os) {
136
+ os_ = &os;
137
+ hasRoot_ = false;
138
+ level_stack_.Clear();
139
+ }
140
+
141
+ //! Checks whether the output is a complete JSON.
142
+ /*!
143
+ A complete JSON has a complete root object or array.
144
+ */
145
+ bool IsComplete() const {
146
+ return hasRoot_ && level_stack_.Empty();
147
+ }
148
+
149
+ int GetMaxDecimalPlaces() const {
150
+ return maxDecimalPlaces_;
151
+ }
152
+
153
+ //! Sets the maximum number of decimal places for double output.
154
+ /*!
155
+ This setting truncates the output with specified number of decimal places.
156
+
157
+ For example,
158
+
159
+ \code
160
+ writer.SetMaxDecimalPlaces(3);
161
+ writer.StartArray();
162
+ writer.Double(0.12345); // "0.123"
163
+ writer.Double(0.0001); // "0.0"
164
+ writer.Double(1.234567890123456e30); // "1.234567890123456e30" (do not truncate significand for positive exponent)
165
+ writer.Double(1.23e-4); // "0.0" (do truncate significand for negative exponent)
166
+ writer.EndArray();
167
+ \endcode
168
+
169
+ The default setting does not truncate any decimal places. You can restore to this setting by calling
170
+ \code
171
+ writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces);
172
+ \endcode
173
+ */
174
+ void SetMaxDecimalPlaces(int maxDecimalPlaces) {
175
+ maxDecimalPlaces_ = maxDecimalPlaces;
176
+ }
177
+
178
+ /*!@name Implementation of Handler
179
+ \see Handler
180
+ */
181
+ //@{
182
+
183
+ bool Null() { Prefix(kNullType); return EndValue(WriteNull()); }
184
+ bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); }
185
+ bool Int(int i) { Prefix(kNumberType); return EndValue(WriteInt(i)); }
186
+ bool Uint(unsigned u) { Prefix(kNumberType); return EndValue(WriteUint(u)); }
187
+ bool Int64(int64_t i64) { Prefix(kNumberType); return EndValue(WriteInt64(i64)); }
188
+ bool Uint64(uint64_t u64) { Prefix(kNumberType); return EndValue(WriteUint64(u64)); }
189
+
190
+ //! Writes the given \c double value to the stream
191
+ /*!
192
+ \param d The value to be written.
193
+ \return Whether it is succeed.
194
+ */
195
+ bool Double(double d) { Prefix(kNumberType); return EndValue(WriteDouble(d)); }
196
+
197
+ bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
198
+ RAPIDJSON_ASSERT(str != 0);
199
+ (void)copy;
200
+ Prefix(kNumberType);
201
+ return EndValue(WriteString(str, length));
202
+ }
203
+
204
+ bool String(const Ch* str, SizeType length, bool copy = false) {
205
+ RAPIDJSON_ASSERT(str != 0);
206
+ (void)copy;
207
+ Prefix(kStringType);
208
+ return EndValue(WriteString(str, length));
209
+ }
210
+
211
+ #if RAPIDJSON_HAS_STDSTRING
212
+ bool String(const std::basic_string<Ch>& str) {
213
+ return String(str.data(), SizeType(str.size()));
214
+ }
215
+ #endif
216
+
217
+ bool StartObject() {
218
+ Prefix(kObjectType);
219
+ new (level_stack_.template Push<Level>()) Level(false);
220
+ return WriteStartObject();
221
+ }
222
+
223
+ bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
224
+
225
+ #if RAPIDJSON_HAS_STDSTRING
226
+ bool Key(const std::basic_string<Ch>& str)
227
+ {
228
+ return Key(str.data(), SizeType(str.size()));
229
+ }
230
+ #endif
231
+
232
+ bool EndObject(SizeType memberCount = 0) {
233
+ (void)memberCount;
234
+ RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object
235
+ RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray); // currently inside an Array, not Object
236
+ RAPIDJSON_ASSERT(0 == level_stack_.template Top<Level>()->valueCount % 2); // Object has a Key without a Value
237
+ level_stack_.template Pop<Level>(1);
238
+ return EndValue(WriteEndObject());
239
+ }
240
+
241
+ bool StartArray() {
242
+ Prefix(kArrayType);
243
+ new (level_stack_.template Push<Level>()) Level(true);
244
+ return WriteStartArray();
245
+ }
246
+
247
+ bool EndArray(SizeType elementCount = 0) {
248
+ (void)elementCount;
249
+ RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
250
+ RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
251
+ level_stack_.template Pop<Level>(1);
252
+ return EndValue(WriteEndArray());
253
+ }
254
+ //@}
255
+
256
+ /*! @name Convenience extensions */
257
+ //@{
258
+
259
+ //! Simpler but slower overload.
260
+ bool String(const Ch* const& str) { return String(str, internal::StrLen(str)); }
261
+ bool Key(const Ch* const& str) { return Key(str, internal::StrLen(str)); }
262
+
263
+ //@}
264
+
265
+ //! Write a raw JSON value.
266
+ /*!
267
+ For user to write a stringified JSON as a value.
268
+
269
+ \param json A well-formed JSON value. It should not contain null character within [0, length - 1] range.
270
+ \param length Length of the json.
271
+ \param type Type of the root of json.
272
+ */
273
+ bool RawValue(const Ch* json, size_t length, Type type) {
274
+ RAPIDJSON_ASSERT(json != 0);
275
+ Prefix(type);
276
+ return EndValue(WriteRawValue(json, length));
277
+ }
278
+
279
+ //! Flush the output stream.
280
+ /*!
281
+ Allows the user to flush the output stream immediately.
282
+ */
283
+ void Flush() {
284
+ os_->Flush();
285
+ }
286
+
287
+ protected:
288
+ //! Information for each nested level
289
+ struct Level {
290
+ Level(bool inArray_) : valueCount(0), inArray(inArray_) {}
291
+ size_t valueCount; //!< number of values in this level
292
+ bool inArray; //!< true if in array, otherwise in object
293
+ };
294
+
295
+ static const size_t kDefaultLevelDepth = 32;
296
+
297
+ bool WriteNull() {
298
+ PutReserve(*os_, 4);
299
+ PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true;
300
+ }
301
+
302
+ bool WriteBool(bool b) {
303
+ if (b) {
304
+ PutReserve(*os_, 4);
305
+ PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'r'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'e');
306
+ }
307
+ else {
308
+ PutReserve(*os_, 5);
309
+ PutUnsafe(*os_, 'f'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 's'); PutUnsafe(*os_, 'e');
310
+ }
311
+ return true;
312
+ }
313
+
314
+ bool WriteInt(int i) {
315
+ char buffer[11];
316
+ const char* end = internal::i32toa(i, buffer);
317
+ PutReserve(*os_, static_cast<size_t>(end - buffer));
318
+ for (const char* p = buffer; p != end; ++p)
319
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
320
+ return true;
321
+ }
322
+
323
+ bool WriteUint(unsigned u) {
324
+ char buffer[10];
325
+ const char* end = internal::u32toa(u, buffer);
326
+ PutReserve(*os_, static_cast<size_t>(end - buffer));
327
+ for (const char* p = buffer; p != end; ++p)
328
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
329
+ return true;
330
+ }
331
+
332
+ bool WriteInt64(int64_t i64) {
333
+ char buffer[21];
334
+ const char* end = internal::i64toa(i64, buffer);
335
+ PutReserve(*os_, static_cast<size_t>(end - buffer));
336
+ for (const char* p = buffer; p != end; ++p)
337
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
338
+ return true;
339
+ }
340
+
341
+ bool WriteUint64(uint64_t u64) {
342
+ char buffer[20];
343
+ char* end = internal::u64toa(u64, buffer);
344
+ PutReserve(*os_, static_cast<size_t>(end - buffer));
345
+ for (char* p = buffer; p != end; ++p)
346
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
347
+ return true;
348
+ }
349
+
350
+ bool WriteDouble(double d) {
351
+ if (internal::Double(d).IsNanOrInf()) {
352
+ if (!(writeFlags & kWriteNanAndInfFlag))
353
+ return false;
354
+ if (internal::Double(d).IsNan()) {
355
+ PutReserve(*os_, 3);
356
+ PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
357
+ return true;
358
+ }
359
+ if (internal::Double(d).Sign()) {
360
+ PutReserve(*os_, 9);
361
+ PutUnsafe(*os_, '-');
362
+ }
363
+ else
364
+ PutReserve(*os_, 8);
365
+ PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
366
+ PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
367
+ return true;
368
+ }
369
+
370
+ char buffer[25];
371
+ char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
372
+ PutReserve(*os_, static_cast<size_t>(end - buffer));
373
+ for (char* p = buffer; p != end; ++p)
374
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(*p));
375
+ return true;
376
+ }
377
+
378
+ bool WriteString(const Ch* str, SizeType length) {
379
+ static const typename OutputStream::Ch hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
380
+ static const char escape[256] = {
381
+ #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
382
+ //0 1 2 3 4 5 6 7 8 9 A B C D E F
383
+ 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
384
+ 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
385
+ 0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
386
+ Z16, Z16, // 30~4F
387
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
388
+ Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
389
+ #undef Z16
390
+ };
391
+
392
+ if (TargetEncoding::supportUnicode)
393
+ PutReserve(*os_, 2 + length * 6); // "\uxxxx..."
394
+ else
395
+ PutReserve(*os_, 2 + length * 12); // "\uxxxx\uyyyy..."
396
+
397
+ PutUnsafe(*os_, '\"');
398
+ GenericStringStream<SourceEncoding> is(str);
399
+ while (ScanWriteUnescapedString(is, length)) {
400
+ const Ch c = is.Peek();
401
+ if (!TargetEncoding::supportUnicode && static_cast<unsigned>(c) >= 0x80) {
402
+ // Unicode escaping
403
+ unsigned codepoint;
404
+ if (RAPIDJSON_UNLIKELY(!SourceEncoding::Decode(is, &codepoint)))
405
+ return false;
406
+ PutUnsafe(*os_, '\\');
407
+ PutUnsafe(*os_, 'u');
408
+ if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)) {
409
+ PutUnsafe(*os_, hexDigits[(codepoint >> 12) & 15]);
410
+ PutUnsafe(*os_, hexDigits[(codepoint >> 8) & 15]);
411
+ PutUnsafe(*os_, hexDigits[(codepoint >> 4) & 15]);
412
+ PutUnsafe(*os_, hexDigits[(codepoint ) & 15]);
413
+ }
414
+ else {
415
+ RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF);
416
+ // Surrogate pair
417
+ unsigned s = codepoint - 0x010000;
418
+ unsigned lead = (s >> 10) + 0xD800;
419
+ unsigned trail = (s & 0x3FF) + 0xDC00;
420
+ PutUnsafe(*os_, hexDigits[(lead >> 12) & 15]);
421
+ PutUnsafe(*os_, hexDigits[(lead >> 8) & 15]);
422
+ PutUnsafe(*os_, hexDigits[(lead >> 4) & 15]);
423
+ PutUnsafe(*os_, hexDigits[(lead ) & 15]);
424
+ PutUnsafe(*os_, '\\');
425
+ PutUnsafe(*os_, 'u');
426
+ PutUnsafe(*os_, hexDigits[(trail >> 12) & 15]);
427
+ PutUnsafe(*os_, hexDigits[(trail >> 8) & 15]);
428
+ PutUnsafe(*os_, hexDigits[(trail >> 4) & 15]);
429
+ PutUnsafe(*os_, hexDigits[(trail ) & 15]);
430
+ }
431
+ }
432
+ else if ((sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256) && RAPIDJSON_UNLIKELY(escape[static_cast<unsigned char>(c)])) {
433
+ is.Take();
434
+ PutUnsafe(*os_, '\\');
435
+ PutUnsafe(*os_, static_cast<typename OutputStream::Ch>(escape[static_cast<unsigned char>(c)]));
436
+ if (escape[static_cast<unsigned char>(c)] == 'u') {
437
+ PutUnsafe(*os_, '0');
438
+ PutUnsafe(*os_, '0');
439
+ PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) >> 4]);
440
+ PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) & 0xF]);
441
+ }
442
+ }
443
+ else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
444
+ Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) :
445
+ Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
446
+ return false;
447
+ }
448
+ PutUnsafe(*os_, '\"');
449
+ return true;
450
+ }
451
+
452
+ bool ScanWriteUnescapedString(GenericStringStream<SourceEncoding>& is, size_t length) {
453
+ return RAPIDJSON_LIKELY(is.Tell() < length);
454
+ }
455
+
456
+ bool WriteStartObject() { os_->Put('{'); return true; }
457
+ bool WriteEndObject() { os_->Put('}'); return true; }
458
+ bool WriteStartArray() { os_->Put('['); return true; }
459
+ bool WriteEndArray() { os_->Put(']'); return true; }
460
+
461
+ bool WriteRawValue(const Ch* json, size_t length) {
462
+ PutReserve(*os_, length);
463
+ GenericStringStream<SourceEncoding> is(json);
464
+ while (RAPIDJSON_LIKELY(is.Tell() < length)) {
465
+ const Ch c = is.Peek();
466
+ RAPIDJSON_ASSERT(c != '\0');
467
+ if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
468
+ Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) :
469
+ Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
470
+ return false;
471
+ }
472
+ return true;
473
+ }
474
+
475
+ void Prefix(Type type) {
476
+ (void)type;
477
+ if (RAPIDJSON_LIKELY(level_stack_.GetSize() != 0)) { // this value is not at root
478
+ Level* level = level_stack_.template Top<Level>();
479
+ if (level->valueCount > 0) {
480
+ if (level->inArray)
481
+ os_->Put(','); // add comma if it is not the first element in array
482
+ else // in object
483
+ os_->Put((level->valueCount % 2 == 0) ? ',' : ':');
484
+ }
485
+ if (!level->inArray && level->valueCount % 2 == 0)
486
+ RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
487
+ level->valueCount++;
488
+ }
489
+ else {
490
+ RAPIDJSON_ASSERT(!hasRoot_); // Should only has one and only one root.
491
+ hasRoot_ = true;
492
+ }
493
+ }
494
+
495
+ // Flush the value if it is the top level one.
496
+ bool EndValue(bool ret) {
497
+ if (RAPIDJSON_UNLIKELY(level_stack_.Empty())) // end of json text
498
+ Flush();
499
+ return ret;
500
+ }
501
+
502
+ OutputStream* os_;
503
+ internal::Stack<StackAllocator> level_stack_;
504
+ int maxDecimalPlaces_;
505
+ bool hasRoot_;
506
+
507
+ private:
508
+ // Prohibit copy constructor & assignment operator.
509
+ Writer(const Writer&);
510
+ Writer& operator=(const Writer&);
511
+ };
512
+
513
+ // Full specialization for StringStream to prevent memory copying
514
+
515
+ template<>
516
+ inline bool Writer<StringBuffer>::WriteInt(int i) {
517
+ char *buffer = os_->Push(11);
518
+ const char* end = internal::i32toa(i, buffer);
519
+ os_->Pop(static_cast<size_t>(11 - (end - buffer)));
520
+ return true;
521
+ }
522
+
523
+ template<>
524
+ inline bool Writer<StringBuffer>::WriteUint(unsigned u) {
525
+ char *buffer = os_->Push(10);
526
+ const char* end = internal::u32toa(u, buffer);
527
+ os_->Pop(static_cast<size_t>(10 - (end - buffer)));
528
+ return true;
529
+ }
530
+
531
+ template<>
532
+ inline bool Writer<StringBuffer>::WriteInt64(int64_t i64) {
533
+ char *buffer = os_->Push(21);
534
+ const char* end = internal::i64toa(i64, buffer);
535
+ os_->Pop(static_cast<size_t>(21 - (end - buffer)));
536
+ return true;
537
+ }
538
+
539
+ template<>
540
+ inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
541
+ char *buffer = os_->Push(20);
542
+ const char* end = internal::u64toa(u, buffer);
543
+ os_->Pop(static_cast<size_t>(20 - (end - buffer)));
544
+ return true;
545
+ }
546
+
547
+ template<>
548
+ inline bool Writer<StringBuffer>::WriteDouble(double d) {
549
+ if (internal::Double(d).IsNanOrInf()) {
550
+ // Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
551
+ if (!(kWriteDefaultFlags & kWriteNanAndInfFlag))
552
+ return false;
553
+ if (internal::Double(d).IsNan()) {
554
+ PutReserve(*os_, 3);
555
+ PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
556
+ return true;
557
+ }
558
+ if (internal::Double(d).Sign()) {
559
+ PutReserve(*os_, 9);
560
+ PutUnsafe(*os_, '-');
561
+ }
562
+ else
563
+ PutReserve(*os_, 8);
564
+ PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
565
+ PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
566
+ return true;
567
+ }
568
+
569
+ char *buffer = os_->Push(25);
570
+ char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
571
+ os_->Pop(static_cast<size_t>(25 - (end - buffer)));
572
+ return true;
573
+ }
574
+
575
+ #if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
576
+ template<>
577
+ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
578
+ if (length < 16)
579
+ return RAPIDJSON_LIKELY(is.Tell() < length);
580
+
581
+ if (!RAPIDJSON_LIKELY(is.Tell() < length))
582
+ return false;
583
+
584
+ const char* p = is.src_;
585
+ const char* end = is.head_ + length;
586
+ const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
587
+ const char* endAligned = reinterpret_cast<const char*>(reinterpret_cast<size_t>(end) & static_cast<size_t>(~15));
588
+ if (nextAligned > end)
589
+ return true;
590
+
591
+ while (p != nextAligned)
592
+ if (*p < 0x20 || *p == '\"' || *p == '\\') {
593
+ is.src_ = p;
594
+ return RAPIDJSON_LIKELY(is.Tell() < length);
595
+ }
596
+ else
597
+ os_->PutUnsafe(*p++);
598
+
599
+ // The rest of string using SIMD
600
+ static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
601
+ static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
602
+ static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
603
+ const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
604
+ const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
605
+ const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
606
+
607
+ for (; p != endAligned; p += 16) {
608
+ const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
609
+ const __m128i t1 = _mm_cmpeq_epi8(s, dq);
610
+ const __m128i t2 = _mm_cmpeq_epi8(s, bs);
611
+ const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
612
+ const __m128i x = _mm_or_si128(_mm_or_si128(t1, t2), t3);
613
+ unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
614
+ if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
615
+ SizeType len;
616
+ #ifdef _MSC_VER // Find the index of first escaped
617
+ unsigned long offset;
618
+ _BitScanForward(&offset, r);
619
+ len = offset;
620
+ #else
621
+ len = static_cast<SizeType>(__builtin_ffs(r) - 1);
622
+ #endif
623
+ char* q = reinterpret_cast<char*>(os_->PushUnsafe(len));
624
+ for (size_t i = 0; i < len; i++)
625
+ q[i] = p[i];
626
+
627
+ p += len;
628
+ break;
629
+ }
630
+ _mm_storeu_si128(reinterpret_cast<__m128i *>(os_->PushUnsafe(16)), s);
631
+ }
632
+
633
+ is.src_ = p;
634
+ return RAPIDJSON_LIKELY(is.Tell() < length);
635
+ }
636
+ #elif defined(RAPIDJSON_NEON)
637
+ template<>
638
+ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
639
+ if (length < 16)
640
+ return RAPIDJSON_LIKELY(is.Tell() < length);
641
+
642
+ if (!RAPIDJSON_LIKELY(is.Tell() < length))
643
+ return false;
644
+
645
+ const char* p = is.src_;
646
+ const char* end = is.head_ + length;
647
+ const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
648
+ const char* endAligned = reinterpret_cast<const char*>(reinterpret_cast<size_t>(end) & static_cast<size_t>(~15));
649
+ if (nextAligned > end)
650
+ return true;
651
+
652
+ while (p != nextAligned)
653
+ if (*p < 0x20 || *p == '\"' || *p == '\\') {
654
+ is.src_ = p;
655
+ return RAPIDJSON_LIKELY(is.Tell() < length);
656
+ }
657
+ else
658
+ os_->PutUnsafe(*p++);
659
+
660
+ // The rest of string using SIMD
661
+ const uint8x16_t s0 = vmovq_n_u8('"');
662
+ const uint8x16_t s1 = vmovq_n_u8('\\');
663
+ const uint8x16_t s2 = vmovq_n_u8('\b');
664
+ const uint8x16_t s3 = vmovq_n_u8(32);
665
+
666
+ for (; p != endAligned; p += 16) {
667
+ const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
668
+ uint8x16_t x = vceqq_u8(s, s0);
669
+ x = vorrq_u8(x, vceqq_u8(s, s1));
670
+ x = vorrq_u8(x, vceqq_u8(s, s2));
671
+ x = vorrq_u8(x, vcltq_u8(s, s3));
672
+
673
+ x = vrev64q_u8(x); // Rev in 64
674
+ uint64_t low = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 0); // extract
675
+ uint64_t high = vgetq_lane_u64(reinterpret_cast<uint64x2_t>(x), 1); // extract
676
+
677
+ SizeType len = 0;
678
+ bool escaped = false;
679
+ if (low == 0) {
680
+ if (high != 0) {
681
+ unsigned lz = (unsigned)__builtin_clzll(high);
682
+ len = 8 + (lz >> 3);
683
+ escaped = true;
684
+ }
685
+ } else {
686
+ unsigned lz = (unsigned)__builtin_clzll(low);
687
+ len = lz >> 3;
688
+ escaped = true;
689
+ }
690
+ if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
691
+ char* q = reinterpret_cast<char*>(os_->PushUnsafe(len));
692
+ for (size_t i = 0; i < len; i++)
693
+ q[i] = p[i];
694
+
695
+ p += len;
696
+ break;
697
+ }
698
+ vst1q_u8(reinterpret_cast<uint8_t *>(os_->PushUnsafe(16)), s);
699
+ }
700
+
701
+ is.src_ = p;
702
+ return RAPIDJSON_LIKELY(is.Tell() < length);
703
+ }
704
+ #endif // RAPIDJSON_NEON
705
+
706
+ RAPIDJSON_NAMESPACE_END
707
+
708
+ #ifdef _MSC_VER
709
+ RAPIDJSON_DIAG_POP
710
+ #endif
711
+
712
+ #ifdef __clang__
713
+ RAPIDJSON_DIAG_POP
714
+ #endif
715
+
716
+ #endif // RAPIDJSON_RAPIDJSON_H_