rj_schema 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +18 -0
- data/ext/rj_schema/extconf.rb +7 -0
- data/ext/rj_schema/rapidjson/CHANGELOG.md +158 -0
- data/ext/rj_schema/rapidjson/CMakeLists.txt +221 -0
- data/ext/rj_schema/rapidjson/CMakeModules/FindGTestSrc.cmake +30 -0
- data/ext/rj_schema/rapidjson/RapidJSON.pc.in +7 -0
- data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +15 -0
- data/ext/rj_schema/rapidjson/RapidJSONConfigVersion.cmake.in +10 -0
- data/ext/rj_schema/rapidjson/appveyor.yml +41 -0
- data/ext/rj_schema/rapidjson/bin/data/glossary.json +22 -0
- data/ext/rj_schema/rapidjson/bin/data/menu.json +27 -0
- data/ext/rj_schema/rapidjson/bin/data/readme.txt +1 -0
- data/ext/rj_schema/rapidjson/bin/data/sample.json +3315 -0
- data/ext/rj_schema/rapidjson/bin/data/webapp.json +88 -0
- data/ext/rj_schema/rapidjson/bin/data/widget.json +26 -0
- data/ext/rj_schema/rapidjson/bin/draft-04/schema +150 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16be.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16bebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16le.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf16lebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32be.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32bebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32le.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf32lebom.json +0 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf8.json +7 -0
- data/ext/rj_schema/rapidjson/bin/encodings/utf8bom.json +7 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail1.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail10.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail11.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail12.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail13.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail14.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail15.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail16.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail17.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail18.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail19.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail2.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail20.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail21.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail22.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail23.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail24.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail25.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail26.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail27.json +2 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail28.json +2 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail29.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail3.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail30.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail31.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail32.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail33.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail4.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail5.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail6.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail7.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail8.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/fail9.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass1.json +58 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass2.json +1 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/pass3.json +6 -0
- data/ext/rj_schema/rapidjson/bin/jsonchecker/readme.txt +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/LICENSE +19 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/README.md +148 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/bin/jsonschema_suite +283 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/folder/folderInteger.json +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/integer.json +3 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/subSchemas.json +8 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalItems.json +82 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalProperties.json +88 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/default.json +49 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/dependencies.json +108 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/disallow.json +80 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/divisibleBy.json +60 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/enum.json +71 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/extends.json +94 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/items.json +46 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maximum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minimum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/bignum.json +107 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/format.json +222 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/jsregex.json +18 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json +15 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/pattern.json +34 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/patternProperties.json +110 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/properties.json +92 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/ref.json +159 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/refRemote.json +74 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/required.json +53 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/type.json +474 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/uniqueItems.json +79 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalItems.json +82 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalProperties.json +88 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/allOf.json +112 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/anyOf.json +68 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/default.json +49 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/definitions.json +32 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/dependencies.json +113 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/enum.json +72 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/items.json +46 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxProperties.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maximum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minItems.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minLength.json +33 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minProperties.json +28 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minimum.json +42 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/multipleOf.json +60 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/not.json +96 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/oneOf.json +68 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/bignum.json +107 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/format.json +148 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json +15 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/pattern.json +34 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/patternProperties.json +110 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/properties.json +92 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/ref.json +159 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/refRemote.json +74 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/required.json +39 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/type.json +330 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/uniqueItems.json +79 -0
- data/ext/rj_schema/rapidjson/bin/jsonschema/tox.ini +8 -0
- data/ext/rj_schema/rapidjson/bin/types/booleans.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/floats.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/guids.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/integers.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/mixed.json +592 -0
- data/ext/rj_schema/rapidjson/bin/types/nulls.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/paragraphs.json +102 -0
- data/ext/rj_schema/rapidjson/bin/types/readme.txt +1 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/LICENSE +45 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/README.md +7 -0
- data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +38 -0
- data/ext/rj_schema/rapidjson/doc/CMakeLists.txt +27 -0
- data/ext/rj_schema/rapidjson/doc/Doxyfile.in +2369 -0
- data/ext/rj_schema/rapidjson/doc/Doxyfile.zh-cn.in +2369 -0
- data/ext/rj_schema/rapidjson/doc/diagram/architecture.dot +50 -0
- data/ext/rj_schema/rapidjson/doc/diagram/architecture.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.dot +65 -0
- data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.dot +62 -0
- data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/makefile +8 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move1.dot +47 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move1.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move2.dot +62 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move2.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move3.dot +60 -0
- data/ext/rj_schema/rapidjson/doc/diagram/move3.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.dot +56 -0
- data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/simpledom.dot +54 -0
- data/ext/rj_schema/rapidjson/doc/diagram/simpledom.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/tutorial.dot +58 -0
- data/ext/rj_schema/rapidjson/doc/diagram/tutorial.png +0 -0
- data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.dot +73 -0
- data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.png +0 -0
- data/ext/rj_schema/rapidjson/doc/dom.md +280 -0
- data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +284 -0
- data/ext/rj_schema/rapidjson/doc/encoding.md +146 -0
- data/ext/rj_schema/rapidjson/doc/encoding.zh-cn.md +152 -0
- data/ext/rj_schema/rapidjson/doc/faq.md +289 -0
- data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +290 -0
- data/ext/rj_schema/rapidjson/doc/features.md +104 -0
- data/ext/rj_schema/rapidjson/doc/features.zh-cn.md +103 -0
- data/ext/rj_schema/rapidjson/doc/internals.md +368 -0
- data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +363 -0
- data/ext/rj_schema/rapidjson/doc/logo/rapidjson.png +0 -0
- data/ext/rj_schema/rapidjson/doc/logo/rapidjson.svg +119 -0
- data/ext/rj_schema/rapidjson/doc/misc/DoxygenLayout.xml +194 -0
- data/ext/rj_schema/rapidjson/doc/misc/doxygenextra.css +274 -0
- data/ext/rj_schema/rapidjson/doc/misc/footer.html +11 -0
- data/ext/rj_schema/rapidjson/doc/misc/header.html +24 -0
- data/ext/rj_schema/rapidjson/doc/npm.md +31 -0
- data/ext/rj_schema/rapidjson/doc/performance.md +26 -0
- data/ext/rj_schema/rapidjson/doc/performance.zh-cn.md +26 -0
- data/ext/rj_schema/rapidjson/doc/pointer.md +234 -0
- data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +234 -0
- data/ext/rj_schema/rapidjson/doc/sax.md +509 -0
- data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +487 -0
- data/ext/rj_schema/rapidjson/doc/schema.md +505 -0
- data/ext/rj_schema/rapidjson/doc/schema.zh-cn.md +237 -0
- data/ext/rj_schema/rapidjson/doc/stream.md +426 -0
- data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +426 -0
- data/ext/rj_schema/rapidjson/doc/tutorial.md +536 -0
- data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +534 -0
- data/ext/rj_schema/rapidjson/docker/debian/Dockerfile +8 -0
- data/ext/rj_schema/rapidjson/example/CMakeLists.txt +45 -0
- data/ext/rj_schema/rapidjson/example/archiver/archiver.cpp +292 -0
- data/ext/rj_schema/rapidjson/example/archiver/archiver.h +145 -0
- data/ext/rj_schema/rapidjson/example/archiver/archivertest.cpp +287 -0
- data/ext/rj_schema/rapidjson/example/capitalize/capitalize.cpp +67 -0
- data/ext/rj_schema/rapidjson/example/condense/condense.cpp +32 -0
- data/ext/rj_schema/rapidjson/example/filterkey/filterkey.cpp +135 -0
- data/ext/rj_schema/rapidjson/example/filterkeydom/filterkeydom.cpp +170 -0
- data/ext/rj_schema/rapidjson/example/jsonx/jsonx.cpp +207 -0
- data/ext/rj_schema/rapidjson/example/lookaheadparser/lookaheadparser.cpp +350 -0
- data/ext/rj_schema/rapidjson/example/messagereader/messagereader.cpp +105 -0
- data/ext/rj_schema/rapidjson/example/parsebyparts/parsebyparts.cpp +176 -0
- data/ext/rj_schema/rapidjson/example/pretty/pretty.cpp +30 -0
- data/ext/rj_schema/rapidjson/example/prettyauto/prettyauto.cpp +56 -0
- data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +78 -0
- data/ext/rj_schema/rapidjson/example/serialize/serialize.cpp +173 -0
- data/ext/rj_schema/rapidjson/example/simpledom/simpledom.cpp +29 -0
- data/ext/rj_schema/rapidjson/example/simplepullreader/simplepullreader.cpp +53 -0
- data/ext/rj_schema/rapidjson/example/simplereader/simplereader.cpp +42 -0
- data/ext/rj_schema/rapidjson/example/simplewriter/simplewriter.cpp +36 -0
- data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +151 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +271 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/document.h +2630 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +299 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +716 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +74 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +161 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +99 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +104 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +151 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +290 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +258 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +245 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +304 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +181 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +55 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +734 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +231 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +69 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +269 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +46 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +115 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +70 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +71 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1363 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +277 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +628 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +2222 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +2479 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +223 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +121 -0
- data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +716 -0
- data/ext/rj_schema/rapidjson/include_dirs.js +2 -0
- data/ext/rj_schema/rapidjson/library.json +15 -0
- data/ext/rj_schema/rapidjson/license.txt +57 -0
- data/ext/rj_schema/rapidjson/package.json +24 -0
- data/ext/rj_schema/rapidjson/rapidjson.autopkg +77 -0
- data/ext/rj_schema/rapidjson/readme.md +160 -0
- data/ext/rj_schema/rapidjson/readme.zh-cn.md +152 -0
- data/ext/rj_schema/rapidjson/test/CMakeLists.txt +20 -0
- data/ext/rj_schema/rapidjson/test/perftest/CMakeLists.txt +28 -0
- data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +974 -0
- data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +24 -0
- data/ext/rj_schema/rapidjson/test/perftest/perftest.h +185 -0
- data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +166 -0
- data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +472 -0
- data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +216 -0
- data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +92 -0
- data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +102 -0
- data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +133 -0
- data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +115 -0
- data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +672 -0
- data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +98 -0
- data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +313 -0
- data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +451 -0
- data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +112 -0
- data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +230 -0
- data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +181 -0
- data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +160 -0
- data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +143 -0
- data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +70 -0
- data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +92 -0
- data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +1529 -0
- data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +344 -0
- data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +1895 -0
- data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +638 -0
- data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +2009 -0
- data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +219 -0
- data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +30 -0
- data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +192 -0
- data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +132 -0
- data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +51 -0
- data/ext/rj_schema/rapidjson/test/unittest/unittest.h +140 -0
- data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1829 -0
- data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +598 -0
- data/ext/rj_schema/rapidjson/test/valgrind.supp +17 -0
- data/ext/rj_schema/rapidjson/travis-doxygen.sh +121 -0
- data/ext/rj_schema/rj_schema.cpp +136 -0
- data/lib/rj_schema.rb +7 -0
- metadata +371 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// JSON filterkey example which populates filtered SAX events into a Document.
|
|
2
|
+
|
|
3
|
+
// This example parses JSON text from stdin with validation.
|
|
4
|
+
// During parsing, specified key will be filtered using a SAX handler.
|
|
5
|
+
// And finally the filtered events are used to populate a Document.
|
|
6
|
+
// As an example, the document is written to standard output.
|
|
7
|
+
|
|
8
|
+
#include "rapidjson/document.h"
|
|
9
|
+
#include "rapidjson/writer.h"
|
|
10
|
+
#include "rapidjson/filereadstream.h"
|
|
11
|
+
#include "rapidjson/filewritestream.h"
|
|
12
|
+
#include "rapidjson/error/en.h"
|
|
13
|
+
#include <stack>
|
|
14
|
+
|
|
15
|
+
using namespace rapidjson;
|
|
16
|
+
|
|
17
|
+
// This handler forwards event into an output handler, with filtering the descendent events of specified key.
|
|
18
|
+
template <typename OutputHandler>
|
|
19
|
+
class FilterKeyHandler {
|
|
20
|
+
public:
|
|
21
|
+
typedef char Ch;
|
|
22
|
+
|
|
23
|
+
FilterKeyHandler(OutputHandler& outputHandler, const Ch* keyString, SizeType keyLength) :
|
|
24
|
+
outputHandler_(outputHandler), keyString_(keyString), keyLength_(keyLength), filterValueDepth_(), filteredKeyCount_()
|
|
25
|
+
{}
|
|
26
|
+
|
|
27
|
+
bool Null() { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Null() && EndValue(); }
|
|
28
|
+
bool Bool(bool b) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Bool(b) && EndValue(); }
|
|
29
|
+
bool Int(int i) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int(i) && EndValue(); }
|
|
30
|
+
bool Uint(unsigned u) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint(u) && EndValue(); }
|
|
31
|
+
bool Int64(int64_t i) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Int64(i) && EndValue(); }
|
|
32
|
+
bool Uint64(uint64_t u) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Uint64(u) && EndValue(); }
|
|
33
|
+
bool Double(double d) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.Double(d) && EndValue(); }
|
|
34
|
+
bool RawNumber(const Ch* str, SizeType len, bool copy) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.RawNumber(str, len, copy) && EndValue(); }
|
|
35
|
+
bool String (const Ch* str, SizeType len, bool copy) { return filterValueDepth_ > 0 ? EndValue() : outputHandler_.String (str, len, copy) && EndValue(); }
|
|
36
|
+
|
|
37
|
+
bool StartObject() {
|
|
38
|
+
if (filterValueDepth_ > 0) {
|
|
39
|
+
filterValueDepth_++;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
filteredKeyCount_.push(0);
|
|
44
|
+
return outputHandler_.StartObject();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
bool Key(const Ch* str, SizeType len, bool copy) {
|
|
49
|
+
if (filterValueDepth_ > 0)
|
|
50
|
+
return true;
|
|
51
|
+
else if (len == keyLength_ && std::memcmp(str, keyString_, len) == 0) {
|
|
52
|
+
filterValueDepth_ = 1;
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
++filteredKeyCount_.top();
|
|
57
|
+
return outputHandler_.Key(str, len, copy);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bool EndObject(SizeType) {
|
|
62
|
+
if (filterValueDepth_ > 0) {
|
|
63
|
+
filterValueDepth_--;
|
|
64
|
+
return EndValue();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Use our own filtered memberCount
|
|
68
|
+
SizeType memberCount = filteredKeyCount_.top();
|
|
69
|
+
filteredKeyCount_.pop();
|
|
70
|
+
return outputHandler_.EndObject(memberCount) && EndValue();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
bool StartArray() {
|
|
75
|
+
if (filterValueDepth_ > 0) {
|
|
76
|
+
filterValueDepth_++;
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
return outputHandler_.StartArray();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
bool EndArray(SizeType elementCount) {
|
|
84
|
+
if (filterValueDepth_ > 0) {
|
|
85
|
+
filterValueDepth_--;
|
|
86
|
+
return EndValue();
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
return outputHandler_.EndArray(elementCount) && EndValue();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private:
|
|
93
|
+
FilterKeyHandler(const FilterKeyHandler&);
|
|
94
|
+
FilterKeyHandler& operator=(const FilterKeyHandler&);
|
|
95
|
+
|
|
96
|
+
bool EndValue() {
|
|
97
|
+
if (filterValueDepth_ == 1) // Just at the end of value after filtered key
|
|
98
|
+
filterValueDepth_ = 0;
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
OutputHandler& outputHandler_;
|
|
103
|
+
const char* keyString_;
|
|
104
|
+
const SizeType keyLength_;
|
|
105
|
+
unsigned filterValueDepth_;
|
|
106
|
+
std::stack<SizeType> filteredKeyCount_;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Implements a generator for Document::Populate()
|
|
110
|
+
template <typename InputStream>
|
|
111
|
+
class FilterKeyReader {
|
|
112
|
+
public:
|
|
113
|
+
typedef char Ch;
|
|
114
|
+
|
|
115
|
+
FilterKeyReader(InputStream& is, const Ch* keyString, SizeType keyLength) :
|
|
116
|
+
is_(is), keyString_(keyString), keyLength_(keyLength), parseResult_()
|
|
117
|
+
{}
|
|
118
|
+
|
|
119
|
+
// SAX event flow: reader -> filter -> handler
|
|
120
|
+
template <typename Handler>
|
|
121
|
+
bool operator()(Handler& handler) {
|
|
122
|
+
FilterKeyHandler<Handler> filter(handler, keyString_, keyLength_);
|
|
123
|
+
Reader reader;
|
|
124
|
+
parseResult_ = reader.Parse(is_, filter);
|
|
125
|
+
return parseResult_;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const ParseResult& GetParseResult() const { return parseResult_; }
|
|
129
|
+
|
|
130
|
+
private:
|
|
131
|
+
FilterKeyReader(const FilterKeyReader&);
|
|
132
|
+
FilterKeyReader& operator=(const FilterKeyReader&);
|
|
133
|
+
|
|
134
|
+
InputStream& is_;
|
|
135
|
+
const char* keyString_;
|
|
136
|
+
const SizeType keyLength_;
|
|
137
|
+
ParseResult parseResult_;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
int main(int argc, char* argv[]) {
|
|
141
|
+
if (argc != 2) {
|
|
142
|
+
fprintf(stderr, "filterkeydom key < input.json > output.json\n");
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Prepare input stream.
|
|
147
|
+
char readBuffer[65536];
|
|
148
|
+
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
|
|
149
|
+
|
|
150
|
+
// Prepare Filter
|
|
151
|
+
FilterKeyReader<FileReadStream> reader(is, argv[1], static_cast<SizeType>(strlen(argv[1])));
|
|
152
|
+
|
|
153
|
+
// Populates the filtered events from reader
|
|
154
|
+
Document document;
|
|
155
|
+
document.Populate(reader);
|
|
156
|
+
ParseResult pr = reader.GetParseResult();
|
|
157
|
+
if (!pr) {
|
|
158
|
+
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(pr.Offset()), GetParseError_En(pr.Code()));
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Prepare JSON writer and output stream.
|
|
163
|
+
char writeBuffer[65536];
|
|
164
|
+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
|
165
|
+
Writer<FileWriteStream> writer(os);
|
|
166
|
+
|
|
167
|
+
// Write the document to standard output
|
|
168
|
+
document.Accept(writer);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// JSON to JSONx conversion exmaple, using SAX API.
|
|
2
|
+
// JSONx is an IBM standard format to represent JSON as XML.
|
|
3
|
+
// https://www-01.ibm.com/support/knowledgecenter/SS9H2Y_7.1.0/com.ibm.dp.doc/json_jsonx.html
|
|
4
|
+
// This example parses JSON text from stdin with validation,
|
|
5
|
+
// and convert to JSONx format to stdout.
|
|
6
|
+
// Need compile with -D__STDC_FORMAT_MACROS for defining PRId64 and PRIu64 macros.
|
|
7
|
+
|
|
8
|
+
#include "rapidjson/reader.h"
|
|
9
|
+
#include "rapidjson/stringbuffer.h"
|
|
10
|
+
#include "rapidjson/filereadstream.h"
|
|
11
|
+
#include "rapidjson/filewritestream.h"
|
|
12
|
+
#include "rapidjson/error/en.h"
|
|
13
|
+
#include <cstdio>
|
|
14
|
+
|
|
15
|
+
using namespace rapidjson;
|
|
16
|
+
|
|
17
|
+
// For simplicity, this example only read/write in UTF-8 encoding
|
|
18
|
+
template <typename OutputStream>
|
|
19
|
+
class JsonxWriter {
|
|
20
|
+
public:
|
|
21
|
+
JsonxWriter(OutputStream& os) : os_(os), name_(), level_(0), hasName_(false) {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
bool Null() {
|
|
25
|
+
return WriteStartElement("null", true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bool Bool(bool b) {
|
|
29
|
+
return
|
|
30
|
+
WriteStartElement("boolean") &&
|
|
31
|
+
WriteString(b ? "true" : "false") &&
|
|
32
|
+
WriteEndElement("boolean");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
bool Int(int i) {
|
|
36
|
+
char buffer[12];
|
|
37
|
+
return WriteNumberElement(buffer, sprintf(buffer, "%d", i));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
bool Uint(unsigned i) {
|
|
41
|
+
char buffer[11];
|
|
42
|
+
return WriteNumberElement(buffer, sprintf(buffer, "%u", i));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
bool Int64(int64_t i) {
|
|
46
|
+
char buffer[21];
|
|
47
|
+
return WriteNumberElement(buffer, sprintf(buffer, "%" PRId64, i));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool Uint64(uint64_t i) {
|
|
51
|
+
char buffer[21];
|
|
52
|
+
return WriteNumberElement(buffer, sprintf(buffer, "%" PRIu64, i));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
bool Double(double d) {
|
|
56
|
+
char buffer[30];
|
|
57
|
+
return WriteNumberElement(buffer, sprintf(buffer, "%.17g", d));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bool RawNumber(const char* str, SizeType length, bool) {
|
|
61
|
+
return
|
|
62
|
+
WriteStartElement("number") &&
|
|
63
|
+
WriteEscapedText(str, length) &&
|
|
64
|
+
WriteEndElement("number");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
bool String(const char* str, SizeType length, bool) {
|
|
68
|
+
return
|
|
69
|
+
WriteStartElement("string") &&
|
|
70
|
+
WriteEscapedText(str, length) &&
|
|
71
|
+
WriteEndElement("string");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
bool StartObject() {
|
|
75
|
+
return WriteStartElement("object");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
bool Key(const char* str, SizeType length, bool) {
|
|
79
|
+
// backup key to name_
|
|
80
|
+
name_.Clear();
|
|
81
|
+
for (SizeType i = 0; i < length; i++)
|
|
82
|
+
name_.Put(str[i]);
|
|
83
|
+
hasName_ = true;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
bool EndObject(SizeType) {
|
|
88
|
+
return WriteEndElement("object");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
bool StartArray() {
|
|
92
|
+
return WriteStartElement("array");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
bool EndArray(SizeType) {
|
|
96
|
+
return WriteEndElement("array");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private:
|
|
100
|
+
bool WriteString(const char* s) {
|
|
101
|
+
while (*s)
|
|
102
|
+
os_.Put(*s++);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
bool WriteEscapedAttributeValue(const char* s, size_t length) {
|
|
107
|
+
for (size_t i = 0; i < length; i++) {
|
|
108
|
+
switch (s[i]) {
|
|
109
|
+
case '&': WriteString("&"); break;
|
|
110
|
+
case '<': WriteString("<"); break;
|
|
111
|
+
case '"': WriteString("""); break;
|
|
112
|
+
default: os_.Put(s[i]); break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
bool WriteEscapedText(const char* s, size_t length) {
|
|
119
|
+
for (size_t i = 0; i < length; i++) {
|
|
120
|
+
switch (s[i]) {
|
|
121
|
+
case '&': WriteString("&"); break;
|
|
122
|
+
case '<': WriteString("<"); break;
|
|
123
|
+
default: os_.Put(s[i]); break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
bool WriteStartElement(const char* type, bool emptyElement = false) {
|
|
130
|
+
if (level_ == 0)
|
|
131
|
+
if (!WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
|
|
132
|
+
return false;
|
|
133
|
+
|
|
134
|
+
if (!WriteString("<json:") || !WriteString(type))
|
|
135
|
+
return false;
|
|
136
|
+
|
|
137
|
+
// For root element, need to add declarations
|
|
138
|
+
if (level_ == 0) {
|
|
139
|
+
if (!WriteString(
|
|
140
|
+
" xsi:schemaLocation=\"http://www.datapower.com/schemas/json jsonx.xsd\""
|
|
141
|
+
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
|
|
142
|
+
" xmlns:json=\"http://www.ibm.com/xmlns/prod/2009/jsonx\""))
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (hasName_) {
|
|
147
|
+
hasName_ = false;
|
|
148
|
+
if (!WriteString(" name=\"") ||
|
|
149
|
+
!WriteEscapedAttributeValue(name_.GetString(), name_.GetSize()) ||
|
|
150
|
+
!WriteString("\""))
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (emptyElement)
|
|
155
|
+
return WriteString("/>");
|
|
156
|
+
else {
|
|
157
|
+
level_++;
|
|
158
|
+
return WriteString(">");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
bool WriteEndElement(const char* type) {
|
|
163
|
+
if (!WriteString("</json:") ||
|
|
164
|
+
!WriteString(type) ||
|
|
165
|
+
!WriteString(">"))
|
|
166
|
+
return false;
|
|
167
|
+
|
|
168
|
+
// For the last end tag, flush the output stream.
|
|
169
|
+
if (--level_ == 0)
|
|
170
|
+
os_.Flush();
|
|
171
|
+
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
bool WriteNumberElement(const char* buffer, int length) {
|
|
176
|
+
if (!WriteStartElement("number"))
|
|
177
|
+
return false;
|
|
178
|
+
for (int j = 0; j < length; j++)
|
|
179
|
+
os_.Put(buffer[j]);
|
|
180
|
+
return WriteEndElement("number");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
OutputStream& os_;
|
|
184
|
+
StringBuffer name_;
|
|
185
|
+
unsigned level_;
|
|
186
|
+
bool hasName_;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
int main(int, char*[]) {
|
|
190
|
+
// Prepare JSON reader and input stream.
|
|
191
|
+
Reader reader;
|
|
192
|
+
char readBuffer[65536];
|
|
193
|
+
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
|
|
194
|
+
|
|
195
|
+
// Prepare JSON writer and output stream.
|
|
196
|
+
char writeBuffer[65536];
|
|
197
|
+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
|
|
198
|
+
JsonxWriter<FileWriteStream> writer(os);
|
|
199
|
+
|
|
200
|
+
// JSON reader parse from the input stream and let writer generate the output.
|
|
201
|
+
if (!reader.Parse(is, writer)) {
|
|
202
|
+
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
#include "rapidjson/reader.h"
|
|
2
|
+
#include "rapidjson/document.h"
|
|
3
|
+
#include <iostream>
|
|
4
|
+
|
|
5
|
+
RAPIDJSON_DIAG_PUSH
|
|
6
|
+
#ifdef __GNUC__
|
|
7
|
+
RAPIDJSON_DIAG_OFF(effc++)
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
// This example demonstrates JSON token-by-token parsing with an API that is
|
|
11
|
+
// more direct; you don't need to design your logic around a handler object and
|
|
12
|
+
// callbacks. Instead, you retrieve values from the JSON stream by calling
|
|
13
|
+
// GetInt(), GetDouble(), GetString() and GetBool(), traverse into structures
|
|
14
|
+
// by calling EnterObject() and EnterArray(), and skip over unwanted data by
|
|
15
|
+
// calling SkipValue(). When you know your JSON's structure, this can be quite
|
|
16
|
+
// convenient.
|
|
17
|
+
//
|
|
18
|
+
// If you aren't sure of what's next in the JSON data, you can use PeekType() and
|
|
19
|
+
// PeekValue() to look ahead to the next object before reading it.
|
|
20
|
+
//
|
|
21
|
+
// If you call the wrong retrieval method--e.g. GetInt when the next JSON token is
|
|
22
|
+
// not an int, EnterObject or EnterArray when there isn't actually an object or array
|
|
23
|
+
// to read--the stream parsing will end immediately and no more data will be delivered.
|
|
24
|
+
//
|
|
25
|
+
// After calling EnterObject, you retrieve keys via NextObjectKey() and values via
|
|
26
|
+
// the normal getters. When NextObjectKey() returns null, you have exited the
|
|
27
|
+
// object, or you can call SkipObject() to skip to the end of the object
|
|
28
|
+
// immediately. If you fetch the entire object (i.e. NextObjectKey() returned null),
|
|
29
|
+
// you should not call SkipObject().
|
|
30
|
+
//
|
|
31
|
+
// After calling EnterArray(), you must alternate between calling NextArrayValue()
|
|
32
|
+
// to see if the array has more data, and then retrieving values via the normal
|
|
33
|
+
// getters. You can call SkipArray() to skip to the end of the array immediately.
|
|
34
|
+
// If you fetch the entire array (i.e. NextArrayValue() returned null),
|
|
35
|
+
// you should not call SkipArray().
|
|
36
|
+
//
|
|
37
|
+
// This parser uses in-situ strings, so the JSON buffer will be altered during the
|
|
38
|
+
// parse.
|
|
39
|
+
|
|
40
|
+
using namespace rapidjson;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class LookaheadParserHandler {
|
|
44
|
+
public:
|
|
45
|
+
bool Null() { st_ = kHasNull; v_.SetNull(); return true; }
|
|
46
|
+
bool Bool(bool b) { st_ = kHasBool; v_.SetBool(b); return true; }
|
|
47
|
+
bool Int(int i) { st_ = kHasNumber; v_.SetInt(i); return true; }
|
|
48
|
+
bool Uint(unsigned u) { st_ = kHasNumber; v_.SetUint(u); return true; }
|
|
49
|
+
bool Int64(int64_t i) { st_ = kHasNumber; v_.SetInt64(i); return true; }
|
|
50
|
+
bool Uint64(uint64_t u) { st_ = kHasNumber; v_.SetUint64(u); return true; }
|
|
51
|
+
bool Double(double d) { st_ = kHasNumber; v_.SetDouble(d); return true; }
|
|
52
|
+
bool RawNumber(const char*, SizeType, bool) { return false; }
|
|
53
|
+
bool String(const char* str, SizeType length, bool) { st_ = kHasString; v_.SetString(str, length); return true; }
|
|
54
|
+
bool StartObject() { st_ = kEnteringObject; return true; }
|
|
55
|
+
bool Key(const char* str, SizeType length, bool) { st_ = kHasKey; v_.SetString(str, length); return true; }
|
|
56
|
+
bool EndObject(SizeType) { st_ = kExitingObject; return true; }
|
|
57
|
+
bool StartArray() { st_ = kEnteringArray; return true; }
|
|
58
|
+
bool EndArray(SizeType) { st_ = kExitingArray; return true; }
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
LookaheadParserHandler(char* str);
|
|
62
|
+
void ParseNext();
|
|
63
|
+
|
|
64
|
+
protected:
|
|
65
|
+
enum LookaheadParsingState {
|
|
66
|
+
kInit,
|
|
67
|
+
kError,
|
|
68
|
+
kHasNull,
|
|
69
|
+
kHasBool,
|
|
70
|
+
kHasNumber,
|
|
71
|
+
kHasString,
|
|
72
|
+
kHasKey,
|
|
73
|
+
kEnteringObject,
|
|
74
|
+
kExitingObject,
|
|
75
|
+
kEnteringArray,
|
|
76
|
+
kExitingArray
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
Value v_;
|
|
80
|
+
LookaheadParsingState st_;
|
|
81
|
+
Reader r_;
|
|
82
|
+
InsituStringStream ss_;
|
|
83
|
+
|
|
84
|
+
static const int parseFlags = kParseDefaultFlags | kParseInsituFlag;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
LookaheadParserHandler::LookaheadParserHandler(char* str) : v_(), st_(kInit), r_(), ss_(str) {
|
|
88
|
+
r_.IterativeParseInit();
|
|
89
|
+
ParseNext();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void LookaheadParserHandler::ParseNext() {
|
|
93
|
+
if (r_.HasParseError()) {
|
|
94
|
+
st_ = kError;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
r_.IterativeParseNext<parseFlags>(ss_, *this);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class LookaheadParser : protected LookaheadParserHandler {
|
|
102
|
+
public:
|
|
103
|
+
LookaheadParser(char* str) : LookaheadParserHandler(str) {}
|
|
104
|
+
|
|
105
|
+
bool EnterObject();
|
|
106
|
+
bool EnterArray();
|
|
107
|
+
const char* NextObjectKey();
|
|
108
|
+
bool NextArrayValue();
|
|
109
|
+
int GetInt();
|
|
110
|
+
double GetDouble();
|
|
111
|
+
const char* GetString();
|
|
112
|
+
bool GetBool();
|
|
113
|
+
void GetNull();
|
|
114
|
+
|
|
115
|
+
void SkipObject();
|
|
116
|
+
void SkipArray();
|
|
117
|
+
void SkipValue();
|
|
118
|
+
Value* PeekValue();
|
|
119
|
+
int PeekType(); // returns a rapidjson::Type, or -1 for no value (at end of object/array)
|
|
120
|
+
|
|
121
|
+
bool IsValid() { return st_ != kError; }
|
|
122
|
+
|
|
123
|
+
protected:
|
|
124
|
+
void SkipOut(int depth);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
bool LookaheadParser::EnterObject() {
|
|
128
|
+
if (st_ != kEnteringObject) {
|
|
129
|
+
st_ = kError;
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
ParseNext();
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
bool LookaheadParser::EnterArray() {
|
|
138
|
+
if (st_ != kEnteringArray) {
|
|
139
|
+
st_ = kError;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
ParseNext();
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const char* LookaheadParser::NextObjectKey() {
|
|
148
|
+
if (st_ == kHasKey) {
|
|
149
|
+
const char* result = v_.GetString();
|
|
150
|
+
ParseNext();
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (st_ != kExitingObject) {
|
|
155
|
+
st_ = kError;
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
ParseNext();
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
bool LookaheadParser::NextArrayValue() {
|
|
164
|
+
if (st_ == kExitingArray) {
|
|
165
|
+
ParseNext();
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (st_ == kError || st_ == kExitingObject || st_ == kHasKey) {
|
|
170
|
+
st_ = kError;
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
int LookaheadParser::GetInt() {
|
|
178
|
+
if (st_ != kHasNumber || !v_.IsInt()) {
|
|
179
|
+
st_ = kError;
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
int result = v_.GetInt();
|
|
184
|
+
ParseNext();
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
double LookaheadParser::GetDouble() {
|
|
189
|
+
if (st_ != kHasNumber) {
|
|
190
|
+
st_ = kError;
|
|
191
|
+
return 0.;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
double result = v_.GetDouble();
|
|
195
|
+
ParseNext();
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
bool LookaheadParser::GetBool() {
|
|
200
|
+
if (st_ != kHasBool) {
|
|
201
|
+
st_ = kError;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
bool result = v_.GetBool();
|
|
206
|
+
ParseNext();
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
void LookaheadParser::GetNull() {
|
|
211
|
+
if (st_ != kHasNull) {
|
|
212
|
+
st_ = kError;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
ParseNext();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const char* LookaheadParser::GetString() {
|
|
220
|
+
if (st_ != kHasString) {
|
|
221
|
+
st_ = kError;
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const char* result = v_.GetString();
|
|
226
|
+
ParseNext();
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
void LookaheadParser::SkipOut(int depth) {
|
|
231
|
+
do {
|
|
232
|
+
if (st_ == kEnteringArray || st_ == kEnteringObject) {
|
|
233
|
+
++depth;
|
|
234
|
+
}
|
|
235
|
+
else if (st_ == kExitingArray || st_ == kExitingObject) {
|
|
236
|
+
--depth;
|
|
237
|
+
}
|
|
238
|
+
else if (st_ == kError) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
ParseNext();
|
|
243
|
+
}
|
|
244
|
+
while (depth > 0);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
void LookaheadParser::SkipValue() {
|
|
248
|
+
SkipOut(0);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
void LookaheadParser::SkipArray() {
|
|
252
|
+
SkipOut(1);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void LookaheadParser::SkipObject() {
|
|
256
|
+
SkipOut(1);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
Value* LookaheadParser::PeekValue() {
|
|
260
|
+
if (st_ >= kHasNull && st_ <= kHasKey) {
|
|
261
|
+
return &v_;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return 0;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
int LookaheadParser::PeekType() {
|
|
268
|
+
if (st_ >= kHasNull && st_ <= kHasKey) {
|
|
269
|
+
return v_.GetType();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (st_ == kEnteringArray) {
|
|
273
|
+
return kArrayType;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (st_ == kEnteringObject) {
|
|
277
|
+
return kObjectType;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return -1;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
//-------------------------------------------------------------------------
|
|
284
|
+
|
|
285
|
+
int main() {
|
|
286
|
+
using namespace std;
|
|
287
|
+
|
|
288
|
+
char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null,"
|
|
289
|
+
"\"i\":123, \"pi\": 3.1416, \"a\":[-1, 2, 3, 4, \"array\", []], \"skipArrays\":[1, 2, [[[3]]]], "
|
|
290
|
+
"\"skipObject\":{ \"i\":0, \"t\":true, \"n\":null, \"d\":123.45 }, "
|
|
291
|
+
"\"skipNested\":[[[[{\"\":0}, {\"\":[-9.87]}]]], [], []], "
|
|
292
|
+
"\"skipString\":\"zzz\", \"reachedEnd\":null, \"t\":true }";
|
|
293
|
+
|
|
294
|
+
LookaheadParser r(json);
|
|
295
|
+
|
|
296
|
+
RAPIDJSON_ASSERT(r.PeekType() == kObjectType);
|
|
297
|
+
|
|
298
|
+
r.EnterObject();
|
|
299
|
+
while (const char* key = r.NextObjectKey()) {
|
|
300
|
+
if (0 == strcmp(key, "hello")) {
|
|
301
|
+
RAPIDJSON_ASSERT(r.PeekType() == kStringType);
|
|
302
|
+
cout << key << ":" << r.GetString() << endl;
|
|
303
|
+
}
|
|
304
|
+
else if (0 == strcmp(key, "t") || 0 == strcmp(key, "f")) {
|
|
305
|
+
RAPIDJSON_ASSERT(r.PeekType() == kTrueType || r.PeekType() == kFalseType);
|
|
306
|
+
cout << key << ":" << r.GetBool() << endl;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
else if (0 == strcmp(key, "n")) {
|
|
310
|
+
RAPIDJSON_ASSERT(r.PeekType() == kNullType);
|
|
311
|
+
r.GetNull();
|
|
312
|
+
cout << key << endl;
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
else if (0 == strcmp(key, "pi")) {
|
|
316
|
+
RAPIDJSON_ASSERT(r.PeekType() == kNumberType);
|
|
317
|
+
cout << key << ":" << r.GetDouble() << endl;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
else if (0 == strcmp(key, "a")) {
|
|
321
|
+
RAPIDJSON_ASSERT(r.PeekType() == kArrayType);
|
|
322
|
+
|
|
323
|
+
r.EnterArray();
|
|
324
|
+
|
|
325
|
+
cout << key << ":[ ";
|
|
326
|
+
while (r.NextArrayValue()) {
|
|
327
|
+
if (r.PeekType() == kNumberType) {
|
|
328
|
+
cout << r.GetDouble() << " ";
|
|
329
|
+
}
|
|
330
|
+
else if (r.PeekType() == kStringType) {
|
|
331
|
+
cout << r.GetString() << " ";
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
r.SkipArray();
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
cout << "]" << endl;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
cout << key << ":skipped" << endl;
|
|
343
|
+
r.SkipValue();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return 0;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
RAPIDJSON_DIAG_POP
|