├── .gitattributes ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CHANGELOG.md ├── CMakeLists.txt ├── CMakeModules └── FindGTestSrc.cmake ├── RapidJSON.pc.in ├── RapidJSONConfig.cmake.in ├── RapidJSONConfigVersion.cmake.in ├── appveyor.yml ├── bin ├── data │ ├── abcde.txt │ ├── glossary.json │ ├── menu.json │ ├── readme.txt │ ├── sample.json │ ├── webapp.json │ └── widget.json ├── draft-04 │ └── schema ├── encodings │ ├── utf16be.json │ ├── utf16bebom.json │ ├── utf16le.json │ ├── utf16lebom.json │ ├── utf32be.json │ ├── utf32bebom.json │ ├── utf32le.json │ ├── utf32lebom.json │ ├── utf8.json │ └── utf8bom.json ├── jsonchecker │ ├── fail1.json │ ├── fail10.json │ ├── fail11.json │ ├── fail12.json │ ├── fail13.json │ ├── fail14.json │ ├── fail15.json │ ├── fail16.json │ ├── fail17.json │ ├── fail18.json │ ├── fail19.json │ ├── fail2.json │ ├── fail20.json │ ├── fail21.json │ ├── fail22.json │ ├── fail23.json │ ├── fail24.json │ ├── fail25.json │ ├── fail26.json │ ├── fail27.json │ ├── fail28.json │ ├── fail29.json │ ├── fail3.json │ ├── fail30.json │ ├── fail31.json │ ├── fail32.json │ ├── fail33.json │ ├── fail4.json │ ├── fail5.json │ ├── fail6.json │ ├── fail7.json │ ├── fail8.json │ ├── fail9.json │ ├── pass1.json │ ├── pass2.json │ ├── pass3.json │ └── readme.txt ├── jsonschema │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── bin │ │ └── jsonschema_suite │ ├── remotes │ │ ├── folder │ │ │ └── folderInteger.json │ │ ├── integer.json │ │ └── subSchemas.json │ ├── tests │ │ ├── draft3 │ │ │ ├── additionalItems.json │ │ │ ├── additionalProperties.json │ │ │ ├── default.json │ │ │ ├── dependencies.json │ │ │ ├── disallow.json │ │ │ ├── divisibleBy.json │ │ │ ├── enum.json │ │ │ ├── extends.json │ │ │ ├── items.json │ │ │ ├── maxItems.json │ │ │ ├── maxLength.json │ │ │ ├── maximum.json │ │ │ ├── minItems.json │ │ │ ├── minLength.json │ │ │ ├── minimum.json │ │ │ ├── optional │ │ │ │ ├── bignum.json │ │ │ │ ├── format.json │ │ │ │ ├── jsregex.json │ │ │ │ └── zeroTerminatedFloats.json │ │ │ ├── pattern.json │ │ │ ├── patternProperties.json │ │ │ ├── properties.json │ │ │ ├── ref.json │ │ │ ├── refRemote.json │ │ │ ├── required.json │ │ │ ├── type.json │ │ │ └── uniqueItems.json │ │ └── draft4 │ │ │ ├── additionalItems.json │ │ │ ├── additionalProperties.json │ │ │ ├── allOf.json │ │ │ ├── anyOf.json │ │ │ ├── default.json │ │ │ ├── definitions.json │ │ │ ├── dependencies.json │ │ │ ├── enum.json │ │ │ ├── items.json │ │ │ ├── maxItems.json │ │ │ ├── maxLength.json │ │ │ ├── maxProperties.json │ │ │ ├── maximum.json │ │ │ ├── minItems.json │ │ │ ├── minLength.json │ │ │ ├── minProperties.json │ │ │ ├── minimum.json │ │ │ ├── multipleOf.json │ │ │ ├── not.json │ │ │ ├── oneOf.json │ │ │ ├── optional │ │ │ ├── bignum.json │ │ │ ├── format.json │ │ │ └── zeroTerminatedFloats.json │ │ │ ├── pattern.json │ │ │ ├── patternProperties.json │ │ │ ├── properties.json │ │ │ ├── ref.json │ │ │ ├── refRemote.json │ │ │ ├── required.json │ │ │ ├── type.json │ │ │ └── uniqueItems.json │ └── tox.ini ├── types │ ├── alotofkeys.json │ ├── booleans.json │ ├── floats.json │ ├── guids.json │ ├── integers.json │ ├── mixed.json │ ├── nulls.json │ ├── paragraphs.json │ └── readme.txt └── unittestschema │ ├── address.json │ ├── allOf_address.json │ ├── anyOf_address.json │ ├── idandref.json │ └── oneOf_address.json ├── contrib └── natvis │ ├── LICENSE │ ├── README.md │ └── rapidjson.natvis ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── Doxyfile.zh-cn.in ├── diagram │ ├── architecture.dot │ ├── architecture.png │ ├── insituparsing.dot │ ├── insituparsing.png │ ├── iterative-parser-states-diagram.dot │ ├── iterative-parser-states-diagram.png │ ├── makefile │ ├── move1.dot │ ├── move1.png │ ├── move2.dot │ ├── move2.png │ ├── move3.dot │ ├── move3.png │ ├── normalparsing.dot │ ├── normalparsing.png │ ├── simpledom.dot │ ├── simpledom.png │ ├── tutorial.dot │ ├── tutorial.png │ ├── utilityclass.dot │ └── utilityclass.png ├── dom.md ├── dom.zh-cn.md ├── encoding.md ├── encoding.zh-cn.md ├── faq.md ├── faq.zh-cn.md ├── features.md ├── features.zh-cn.md ├── internals.md ├── internals.zh-cn.md ├── logo │ ├── rapidjson.png │ └── rapidjson.svg ├── misc │ ├── DoxygenLayout.xml │ ├── doxygenextra.css │ ├── footer.html │ └── header.html ├── npm.md ├── performance.md ├── performance.zh-cn.md ├── pointer.md ├── pointer.zh-cn.md ├── sax.md ├── sax.zh-cn.md ├── schema.md ├── schema.zh-cn.md ├── stream.md ├── stream.zh-cn.md ├── tutorial.md └── tutorial.zh-cn.md ├── docker └── debian │ └── Dockerfile ├── example ├── CMakeLists.txt ├── archiver │ ├── archiver.cpp │ ├── archiver.h │ └── archivertest.cpp ├── capitalize │ └── capitalize.cpp ├── condense │ └── condense.cpp ├── filterkey │ └── filterkey.cpp ├── filterkeydom │ └── filterkeydom.cpp ├── jsonx │ └── jsonx.cpp ├── lookaheadparser │ └── lookaheadparser.cpp ├── messagereader │ └── messagereader.cpp ├── parsebyparts │ └── parsebyparts.cpp ├── pretty │ └── pretty.cpp ├── prettyauto │ └── prettyauto.cpp ├── schemavalidator │ └── schemavalidator.cpp ├── serialize │ └── serialize.cpp ├── simpledom │ └── simpledom.cpp ├── simplepullreader │ └── simplepullreader.cpp ├── simplereader │ └── simplereader.cpp ├── simplewriter │ └── simplewriter.cpp ├── sortkeys │ └── sortkeys.cpp ├── traverseaspointer.cpp └── tutorial │ └── tutorial.cpp ├── include └── rapidjson │ ├── allocators.h │ ├── cursorstreamwrapper.h │ ├── document.h │ ├── encodedstream.h │ ├── encodings.h │ ├── error │ ├── en.h │ └── error.h │ ├── filereadstream.h │ ├── filewritestream.h │ ├── fwd.h │ ├── internal │ ├── biginteger.h │ ├── clzll.h │ ├── diyfp.h │ ├── dtoa.h │ ├── ieee754.h │ ├── itoa.h │ ├── meta.h │ ├── pow10.h │ ├── regex.h │ ├── stack.h │ ├── strfunc.h │ ├── strtod.h │ └── swap.h │ ├── istreamwrapper.h │ ├── memorybuffer.h │ ├── memorystream.h │ ├── msinttypes │ ├── inttypes.h │ └── stdint.h │ ├── ostreamwrapper.h │ ├── pointer.h │ ├── prettywriter.h │ ├── rapidjson.h │ ├── reader.h │ ├── schema.h │ ├── stream.h │ ├── stringbuffer.h │ ├── uri.h │ └── writer.h ├── include_dirs.js ├── library.json ├── license.txt ├── package.json ├── rapidjson.autopkg ├── readme.md ├── readme.zh-cn.md ├── test ├── CMakeLists.txt ├── perftest │ ├── CMakeLists.txt │ ├── misctest.cpp │ ├── perftest.cpp │ ├── perftest.h │ ├── platformtest.cpp │ ├── rapidjsontest.cpp │ └── schematest.cpp ├── unittest │ ├── CMakeLists.txt │ ├── allocatorstest.cpp │ ├── bigintegertest.cpp │ ├── clzlltest.cpp │ ├── cursorstreamwrappertest.cpp │ ├── documenttest.cpp │ ├── dtoatest.cpp │ ├── encodedstreamtest.cpp │ ├── encodingstest.cpp │ ├── filestreamtest.cpp │ ├── fwdtest.cpp │ ├── istreamwrappertest.cpp │ ├── itoatest.cpp │ ├── jsoncheckertest.cpp │ ├── namespacetest.cpp │ ├── ostreamwrappertest.cpp │ ├── platformtest.cpp │ ├── pointertest.cpp │ ├── prettywritertest.cpp │ ├── readertest.cpp │ ├── regextest.cpp │ ├── schematest.cpp │ ├── simdtest.cpp │ ├── strfunctest.cpp │ ├── stringbuffertest.cpp │ ├── strtodtest.cpp │ ├── unittest.cpp │ ├── unittest.h │ ├── uritest.cpp │ ├── valuetest.cpp │ └── writertest.cpp └── valgrind.supp └── travis-doxygen.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.cpp text 7 | *.h text 8 | *.txt text 9 | *.md text 10 | *.cmake text 11 | *.svg text 12 | *.dot text 13 | *.yml text 14 | *.in text 15 | *.sh text 16 | *.autopkg text 17 | Dockerfile text 18 | 19 | # Denote all files that are truly binary and should not be modified. 20 | *.png binary 21 | *.jpg binary 22 | *.json binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/* 2 | !/bin/data 3 | !/bin/encodings 4 | !/bin/jsonchecker 5 | !/bin/types 6 | !/bin/unittestschema 7 | /build 8 | /doc/html 9 | /doc/doxygen_*.db 10 | *.a 11 | 12 | # Temporary files created during CMake build 13 | CMakeCache.txt 14 | CMakeFiles 15 | cmake_install.cmake 16 | CTestTestfile.cmake 17 | Makefile 18 | RapidJSON*.cmake 19 | RapidJSON.pc 20 | Testing 21 | /googletest 22 | install_manifest.txt 23 | Doxyfile 24 | Doxyfile.zh-cn 25 | DartConfiguration.tcl 26 | *.nupkg 27 | 28 | # Files created by OS 29 | *.DS_Store 30 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/gtest"] 2 | path = thirdparty/gtest 3 | url = https://github.com/google/googletest.git 4 | -------------------------------------------------------------------------------- /CMakeModules/FindGTestSrc.cmake: -------------------------------------------------------------------------------- 1 | 2 | SET(GTEST_SEARCH_PATH 3 | "${GTEST_SOURCE_DIR}" 4 | "${CMAKE_CURRENT_LIST_DIR}/../thirdparty/gtest/googletest") 5 | 6 | IF(UNIX) 7 | IF(RAPIDJSON_BUILD_THIRDPARTY_GTEST) 8 | LIST(APPEND GTEST_SEARCH_PATH "/usr/src/gtest") 9 | ELSE() 10 | LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest") 11 | ENDIF() 12 | ENDIF() 13 | 14 | FIND_PATH(GTEST_SOURCE_DIR 15 | NAMES CMakeLists.txt src/gtest_main.cc 16 | PATHS ${GTEST_SEARCH_PATH}) 17 | 18 | 19 | # Debian installs gtest include directory in /usr/include, thus need to look 20 | # for include directory separately from source directory. 21 | FIND_PATH(GTEST_INCLUDE_DIR 22 | NAMES gtest/gtest.h 23 | PATH_SUFFIXES include 24 | HINTS ${GTEST_SOURCE_DIR} 25 | PATHS ${GTEST_SEARCH_PATH}) 26 | 27 | INCLUDE(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(GTestSrc DEFAULT_MSG 29 | GTEST_SOURCE_DIR 30 | GTEST_INCLUDE_DIR) 31 | -------------------------------------------------------------------------------- /RapidJSON.pc.in: -------------------------------------------------------------------------------- 1 | includedir=@INCLUDE_INSTALL_DIR@ 2 | 3 | Name: @PROJECT_NAME@ 4 | Description: A fast JSON parser/generator for C++ with both SAX/DOM style API 5 | Version: @LIB_VERSION_STRING@ 6 | URL: https://github.com/Tencent/rapidjson 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /RapidJSONConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include ("${CMAKE_CURRENT_LIST_DIR}/RapidJSON-targets.cmake") 4 | 5 | ################################################################################ 6 | # RapidJSON source dir 7 | set( RapidJSON_SOURCE_DIR "@CONFIG_SOURCE_DIR@") 8 | 9 | ################################################################################ 10 | # RapidJSON build dir 11 | set( RapidJSON_DIR "@CONFIG_DIR@") 12 | 13 | ################################################################################ 14 | # Compute paths 15 | get_filename_component(RapidJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 16 | 17 | get_target_property(RapidJSON_INCLUDE_DIR RapidJSON INTERFACE_INCLUDE_DIRECTORIES) 18 | 19 | set( RapidJSON_INCLUDE_DIRS ${RapidJSON_INCLUDE_DIR} ) 20 | 21 | if(NOT TARGET rapidjson) 22 | add_library(rapidjson ALIAS RapidJSON) 23 | endif() 24 | -------------------------------------------------------------------------------- /RapidJSONConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | SET(PACKAGE_VERSION "@LIB_VERSION_STRING@") 2 | 3 | IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) 4 | SET(PACKAGE_VERSION_EXACT "true") 5 | ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) 6 | IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 7 | SET(PACKAGE_VERSION_COMPATIBLE "true") 8 | ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 9 | SET(PACKAGE_VERSION_UNSUITABLE "true") 10 | ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 11 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.1.0.{build} 2 | 3 | configuration: 4 | - Debug 5 | - Release 6 | 7 | environment: 8 | matrix: 9 | # - VS_VERSION: 9 2008 10 | # VS_PLATFORM: win32 11 | # - VS_VERSION: 9 2008 12 | # VS_PLATFORM: x64 13 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 14 | VS_VERSION: 10 2010 15 | VS_PLATFORM: win32 16 | CXX11: OFF 17 | CXX17: OFF 18 | CXX20: OFF 19 | MEMBERSMAP: OFF 20 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 21 | VS_VERSION: 10 2010 22 | VS_PLATFORM: x64 23 | CXX11: OFF 24 | CXX17: OFF 25 | CXX20: OFF 26 | MEMBERSMAP: ON 27 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 28 | VS_VERSION: 11 2012 29 | VS_PLATFORM: win32 30 | CXX11: OFF 31 | CXX17: OFF 32 | CXX20: OFF 33 | MEMBERSMAP: ON 34 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 35 | VS_VERSION: 11 2012 36 | VS_PLATFORM: x64 37 | CXX11: OFF 38 | CXX17: OFF 39 | CXX20: OFF 40 | MEMBERSMAP: OFF 41 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 42 | VS_VERSION: 12 2013 43 | VS_PLATFORM: win32 44 | CXX11: OFF 45 | CXX17: OFF 46 | CXX20: OFF 47 | MEMBERSMAP: OFF 48 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 49 | VS_VERSION: 12 2013 50 | VS_PLATFORM: x64 51 | CXX11: OFF 52 | CXX17: OFF 53 | CXX20: OFF 54 | MEMBERSMAP: ON 55 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 56 | VS_VERSION: 14 2015 57 | VS_PLATFORM: win32 58 | CXX11: OFF 59 | CXX17: OFF 60 | CXX20: OFF 61 | MEMBERSMAP: ON 62 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 63 | VS_VERSION: 14 2015 64 | VS_PLATFORM: x64 65 | CXX11: OFF 66 | CXX17: OFF 67 | CXX20: OFF 68 | MEMBERSMAP: OFF 69 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 70 | VS_VERSION: 15 2017 71 | VS_PLATFORM: win32 72 | CXX11: OFF 73 | CXX17: OFF 74 | CXX20: OFF 75 | MEMBERSMAP: OFF 76 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 77 | VS_VERSION: 15 2017 78 | VS_PLATFORM: x64 79 | CXX11: OFF 80 | CXX17: OFF 81 | CXX20: OFF 82 | MEMBERSMAP: ON 83 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 84 | VS_VERSION: 15 2017 85 | VS_PLATFORM: x64 86 | CXX11: ON 87 | CXX17: OFF 88 | CXX20: OFF 89 | MEMBERSMAP: OFF 90 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 91 | VS_VERSION: 15 2017 92 | VS_PLATFORM: x64 93 | CXX11: OFF 94 | CXX17: ON 95 | CXX20: OFF 96 | MEMBERSMAP: OFF 97 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 98 | VS_VERSION: 16 2019 99 | VS_PLATFORM: x64 100 | CXX11: OFF 101 | CXX17: ON 102 | CXX20: OFF 103 | MEMBERSMAP: ON 104 | 105 | before_build: 106 | - git submodule update --init --recursive 107 | - cmake -H. -BBuild/VS -G "Visual Studio %VS_VERSION%" -DCMAKE_GENERATOR_PLATFORM=%VS_PLATFORM% -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_SHARED_LIBS=true -DRAPIDJSON_BUILD_CXX11=%CXX11% -DRAPIDJSON_BUILD_CXX17=%CXX17% -DRAPIDJSON_BUILD_CXX20=%CXX20% -DRAPIDJSON_USE_MEMBERSMAP=%MEMBERSMAP% -Wno-dev 108 | 109 | build: 110 | project: Build\VS\RapidJSON.sln 111 | parallel: true 112 | verbosity: minimal 113 | 114 | test_script: 115 | - cd Build\VS && if %CONFIGURATION%==Debug (ctest --verbose -E perftest --build-config %CONFIGURATION%) else (ctest --verbose --build-config %CONFIGURATION%) 116 | -------------------------------------------------------------------------------- /bin/data/abcde.txt: -------------------------------------------------------------------------------- 1 | abcde -------------------------------------------------------------------------------- /bin/data/glossary.json: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /bin/data/menu.json: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "header": "SVG Viewer", 3 | "items": [ 4 | {"id": "Open"}, 5 | {"id": "OpenNew", "label": "Open New"}, 6 | null, 7 | {"id": "ZoomIn", "label": "Zoom In"}, 8 | {"id": "ZoomOut", "label": "Zoom Out"}, 9 | {"id": "OriginalView", "label": "Original View"}, 10 | null, 11 | {"id": "Quality"}, 12 | {"id": "Pause"}, 13 | {"id": "Mute"}, 14 | null, 15 | {"id": "Find", "label": "Find..."}, 16 | {"id": "FindAgain", "label": "Find Again"}, 17 | {"id": "Copy"}, 18 | {"id": "CopyAgain", "label": "Copy Again"}, 19 | {"id": "CopySVG", "label": "Copy SVG"}, 20 | {"id": "ViewSVG", "label": "View SVG"}, 21 | {"id": "ViewSource", "label": "View Source"}, 22 | {"id": "SaveAs", "label": "Save As"}, 23 | null, 24 | {"id": "Help"}, 25 | {"id": "About", "label": "About Adobe CVG Viewer..."} 26 | ] 27 | }} -------------------------------------------------------------------------------- /bin/data/readme.txt: -------------------------------------------------------------------------------- 1 | sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip 2 | -------------------------------------------------------------------------------- /bin/data/widget.json: -------------------------------------------------------------------------------- 1 | {"widget": { 2 | "debug": "on", 3 | "window": { 4 | "title": "Sample Konfabulator Widget", 5 | "name": "main_window", 6 | "width": 500, 7 | "height": 500 8 | }, 9 | "image": { 10 | "src": "Images/Sun.png", 11 | "name": "sun1", 12 | "hOffset": 250, 13 | "vOffset": 250, 14 | "alignment": "center" 15 | }, 16 | "text": { 17 | "data": "Click Here", 18 | "size": 36, 19 | "style": "bold", 20 | "name": "text1", 21 | "hOffset": 250, 22 | "vOffset": 100, 23 | "alignment": "center", 24 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" 25 | } 26 | }} -------------------------------------------------------------------------------- /bin/encodings/utf16be.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf16be.json -------------------------------------------------------------------------------- /bin/encodings/utf16bebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf16bebom.json -------------------------------------------------------------------------------- /bin/encodings/utf16le.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf16le.json -------------------------------------------------------------------------------- /bin/encodings/utf16lebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf16lebom.json -------------------------------------------------------------------------------- /bin/encodings/utf32be.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf32be.json -------------------------------------------------------------------------------- /bin/encodings/utf32bebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf32bebom.json -------------------------------------------------------------------------------- /bin/encodings/utf32le.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf32le.json -------------------------------------------------------------------------------- /bin/encodings/utf32lebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/bin/encodings/utf32lebom.json -------------------------------------------------------------------------------- /bin/encodings/utf8.json: -------------------------------------------------------------------------------- 1 | { 2 | "en":"I can eat glass and it doesn't hurt me.", 3 | "zh-Hant":"我能吞下玻璃而不傷身體。", 4 | "zh-Hans":"我能吞下玻璃而不伤身体。", 5 | "ja":"私はガラスを食べられます。それは私を傷つけません。", 6 | "ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요" 7 | } -------------------------------------------------------------------------------- /bin/encodings/utf8bom.json: -------------------------------------------------------------------------------- 1 | { 2 | "en":"I can eat glass and it doesn't hurt me.", 3 | "zh-Hant":"我能吞下玻璃而不傷身體。", 4 | "zh-Hans":"我能吞下玻璃而不伤身体。", 5 | "ja":"私はガラスを食べられます。それは私を傷つけません。", 6 | "ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요" 7 | } -------------------------------------------------------------------------------- /bin/jsonchecker/fail1.json: -------------------------------------------------------------------------------- 1 | "A JSON payload should be an object or array, not a string." -------------------------------------------------------------------------------- /bin/jsonchecker/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /bin/jsonchecker/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /bin/jsonchecker/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /bin/jsonchecker/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /bin/jsonchecker/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /bin/jsonchecker/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /bin/jsonchecker/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /bin/jsonchecker/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /bin/jsonchecker/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /bin/jsonchecker/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /bin/jsonchecker/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /bin/jsonchecker/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /bin/jsonchecker/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /bin/jsonchecker/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /bin/jsonchecker/fail23.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /bin/jsonchecker/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /bin/jsonchecker/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /bin/jsonchecker/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /bin/jsonchecker/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /bin/jsonchecker/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /bin/jsonchecker/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /bin/jsonchecker/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /bin/jsonchecker/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /bin/jsonchecker/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /bin/jsonchecker/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /bin/jsonchecker/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /bin/jsonchecker/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /bin/jsonchecker/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /bin/jsonchecker/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /bin/jsonchecker/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /bin/jsonchecker/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /bin/jsonchecker/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /bin/jsonchecker/pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /bin/jsonchecker/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /bin/jsonchecker/pass3.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /bin/jsonchecker/readme.txt: -------------------------------------------------------------------------------- 1 | Test suite from http://json.org/JSON_checker/. 2 | 3 | If the JSON_checker is working correctly, it must accept all of the pass*.json files and reject all of the fail*.json files. 4 | -------------------------------------------------------------------------------- /bin/jsonschema/.gitignore: -------------------------------------------------------------------------------- 1 | TODO 2 | -------------------------------------------------------------------------------- /bin/jsonschema/.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: "2.7" 3 | install: pip install jsonschema 4 | script: bin/jsonschema_suite check 5 | -------------------------------------------------------------------------------- /bin/jsonschema/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Julian Berman 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /bin/jsonschema/remotes/folder/folderInteger.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "integer" 3 | } -------------------------------------------------------------------------------- /bin/jsonschema/remotes/integer.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "integer" 3 | } -------------------------------------------------------------------------------- /bin/jsonschema/remotes/subSchemas.json: -------------------------------------------------------------------------------- 1 | { 2 | "integer": { 3 | "type": "integer" 4 | }, 5 | "refToInteger": { 6 | "$ref": "#/integer" 7 | } 8 | } -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/additionalItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "additionalItems as schema", 4 | "schema": { 5 | "items": [], 6 | "additionalItems": {"type": "integer"} 7 | }, 8 | "tests": [ 9 | { 10 | "description": "additional items match schema", 11 | "data": [ 1, 2, 3, 4 ], 12 | "valid": true 13 | }, 14 | { 15 | "description": "additional items do not match schema", 16 | "data": [ 1, 2, 3, "foo" ], 17 | "valid": false 18 | } 19 | ] 20 | }, 21 | { 22 | "description": "items is schema, no additionalItems", 23 | "schema": { 24 | "items": {}, 25 | "additionalItems": false 26 | }, 27 | "tests": [ 28 | { 29 | "description": "all items match schema", 30 | "data": [ 1, 2, 3, 4, 5 ], 31 | "valid": true 32 | } 33 | ] 34 | }, 35 | { 36 | "description": "array of items with no additionalItems", 37 | "schema": { 38 | "items": [{}, {}, {}], 39 | "additionalItems": false 40 | }, 41 | "tests": [ 42 | { 43 | "description": "no additional items present", 44 | "data": [ 1, 2, 3 ], 45 | "valid": true 46 | }, 47 | { 48 | "description": "additional items are not permitted", 49 | "data": [ 1, 2, 3, 4 ], 50 | "valid": false 51 | } 52 | ] 53 | }, 54 | { 55 | "description": "additionalItems as false without items", 56 | "schema": {"additionalItems": false}, 57 | "tests": [ 58 | { 59 | "description": 60 | "items defaults to empty schema so everything is valid", 61 | "data": [ 1, 2, 3, 4, 5 ], 62 | "valid": true 63 | }, 64 | { 65 | "description": "ignores non-arrays", 66 | "data": {"foo" : "bar"}, 67 | "valid": true 68 | } 69 | ] 70 | }, 71 | { 72 | "description": "additionalItems are allowed by default", 73 | "schema": {"items": []}, 74 | "tests": [ 75 | { 76 | "description": "only the first items are validated", 77 | "data": [1, "foo", false], 78 | "valid": true 79 | } 80 | ] 81 | } 82 | ] 83 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/additionalProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": 4 | "additionalProperties being false does not allow other properties", 5 | "schema": { 6 | "properties": {"foo": {}, "bar": {}}, 7 | "patternProperties": { "^v": {} }, 8 | "additionalProperties": false 9 | }, 10 | "tests": [ 11 | { 12 | "description": "no additional properties is valid", 13 | "data": {"foo": 1}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "an additional property is invalid", 18 | "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-objects", 23 | "data": [1, 2, 3], 24 | "valid": true 25 | }, 26 | { 27 | "description": "patternProperties are not additional properties", 28 | "data": {"foo":1, "vroom": 2}, 29 | "valid": true 30 | } 31 | ] 32 | }, 33 | { 34 | "description": 35 | "additionalProperties allows a schema which should validate", 36 | "schema": { 37 | "properties": {"foo": {}, "bar": {}}, 38 | "additionalProperties": {"type": "boolean"} 39 | }, 40 | "tests": [ 41 | { 42 | "description": "no additional properties is valid", 43 | "data": {"foo": 1}, 44 | "valid": true 45 | }, 46 | { 47 | "description": "an additional valid property is valid", 48 | "data": {"foo" : 1, "bar" : 2, "quux" : true}, 49 | "valid": true 50 | }, 51 | { 52 | "description": "an additional invalid property is invalid", 53 | "data": {"foo" : 1, "bar" : 2, "quux" : 12}, 54 | "valid": false 55 | } 56 | ] 57 | }, 58 | { 59 | "description": 60 | "additionalProperties can exist by itself", 61 | "schema": { 62 | "additionalProperties": {"type": "boolean"} 63 | }, 64 | "tests": [ 65 | { 66 | "description": "an additional valid property is valid", 67 | "data": {"foo" : true}, 68 | "valid": true 69 | }, 70 | { 71 | "description": "an additional invalid property is invalid", 72 | "data": {"foo" : 1}, 73 | "valid": false 74 | } 75 | ] 76 | }, 77 | { 78 | "description": "additionalProperties are allowed by default", 79 | "schema": {"properties": {"foo": {}, "bar": {}}}, 80 | "tests": [ 81 | { 82 | "description": "additional properties are allowed", 83 | "data": {"foo": 1, "bar": 2, "quux": true}, 84 | "valid": true 85 | } 86 | ] 87 | } 88 | ] 89 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/default.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "invalid type for default", 4 | "schema": { 5 | "properties": { 6 | "foo": { 7 | "type": "integer", 8 | "default": [] 9 | } 10 | } 11 | }, 12 | "tests": [ 13 | { 14 | "description": "valid when property is specified", 15 | "data": {"foo": 13}, 16 | "valid": true 17 | }, 18 | { 19 | "description": "still valid when the invalid default is used", 20 | "data": {}, 21 | "valid": true 22 | } 23 | ] 24 | }, 25 | { 26 | "description": "invalid string value for default", 27 | "schema": { 28 | "properties": { 29 | "bar": { 30 | "type": "string", 31 | "minLength": 4, 32 | "default": "bad" 33 | } 34 | } 35 | }, 36 | "tests": [ 37 | { 38 | "description": "valid when property is specified", 39 | "data": {"bar": "good"}, 40 | "valid": true 41 | }, 42 | { 43 | "description": "still valid when the invalid default is used", 44 | "data": {}, 45 | "valid": true 46 | } 47 | ] 48 | } 49 | ] 50 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/dependencies.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "dependencies", 4 | "schema": { 5 | "dependencies": {"bar": "foo"} 6 | }, 7 | "tests": [ 8 | { 9 | "description": "neither", 10 | "data": {}, 11 | "valid": true 12 | }, 13 | { 14 | "description": "nondependant", 15 | "data": {"foo": 1}, 16 | "valid": true 17 | }, 18 | { 19 | "description": "with dependency", 20 | "data": {"foo": 1, "bar": 2}, 21 | "valid": true 22 | }, 23 | { 24 | "description": "missing dependency", 25 | "data": {"bar": 2}, 26 | "valid": false 27 | }, 28 | { 29 | "description": "ignores non-objects", 30 | "data": "foo", 31 | "valid": true 32 | } 33 | ] 34 | }, 35 | { 36 | "description": "multiple dependencies", 37 | "schema": { 38 | "dependencies": {"quux": ["foo", "bar"]} 39 | }, 40 | "tests": [ 41 | { 42 | "description": "neither", 43 | "data": {}, 44 | "valid": true 45 | }, 46 | { 47 | "description": "nondependants", 48 | "data": {"foo": 1, "bar": 2}, 49 | "valid": true 50 | }, 51 | { 52 | "description": "with dependencies", 53 | "data": {"foo": 1, "bar": 2, "quux": 3}, 54 | "valid": true 55 | }, 56 | { 57 | "description": "missing dependency", 58 | "data": {"foo": 1, "quux": 2}, 59 | "valid": false 60 | }, 61 | { 62 | "description": "missing other dependency", 63 | "data": {"bar": 1, "quux": 2}, 64 | "valid": false 65 | }, 66 | { 67 | "description": "missing both dependencies", 68 | "data": {"quux": 1}, 69 | "valid": false 70 | } 71 | ] 72 | }, 73 | { 74 | "description": "multiple dependencies subschema", 75 | "schema": { 76 | "dependencies": { 77 | "bar": { 78 | "properties": { 79 | "foo": {"type": "integer"}, 80 | "bar": {"type": "integer"} 81 | } 82 | } 83 | } 84 | }, 85 | "tests": [ 86 | { 87 | "description": "valid", 88 | "data": {"foo": 1, "bar": 2}, 89 | "valid": true 90 | }, 91 | { 92 | "description": "wrong type", 93 | "data": {"foo": "quux", "bar": 2}, 94 | "valid": false 95 | }, 96 | { 97 | "description": "wrong type other", 98 | "data": {"foo": 2, "bar": "quux"}, 99 | "valid": false 100 | }, 101 | { 102 | "description": "wrong type both", 103 | "data": {"foo": "quux", "bar": "quux"}, 104 | "valid": false 105 | } 106 | ] 107 | } 108 | ] 109 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/disallow.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "disallow", 4 | "schema": { 5 | "disallow": "integer" 6 | }, 7 | "tests": [ 8 | { 9 | "description": "allowed", 10 | "data": "foo", 11 | "valid": true 12 | }, 13 | { 14 | "description": "disallowed", 15 | "data": 1, 16 | "valid": false 17 | } 18 | ] 19 | }, 20 | { 21 | "description": "multiple disallow", 22 | "schema": { 23 | "disallow": ["integer", "boolean"] 24 | }, 25 | "tests": [ 26 | { 27 | "description": "valid", 28 | "data": "foo", 29 | "valid": true 30 | }, 31 | { 32 | "description": "mismatch", 33 | "data": 1, 34 | "valid": false 35 | }, 36 | { 37 | "description": "other mismatch", 38 | "data": true, 39 | "valid": false 40 | } 41 | ] 42 | }, 43 | { 44 | "description": "multiple disallow subschema", 45 | "schema": { 46 | "disallow": 47 | ["string", 48 | { 49 | "type": "object", 50 | "properties": { 51 | "foo": { 52 | "type": "string" 53 | } 54 | } 55 | }] 56 | }, 57 | "tests": [ 58 | { 59 | "description": "match", 60 | "data": 1, 61 | "valid": true 62 | }, 63 | { 64 | "description": "other match", 65 | "data": {"foo": 1}, 66 | "valid": true 67 | }, 68 | { 69 | "description": "mismatch", 70 | "data": "foo", 71 | "valid": false 72 | }, 73 | { 74 | "description": "other mismatch", 75 | "data": {"foo": "bar"}, 76 | "valid": false 77 | } 78 | ] 79 | } 80 | ] 81 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/divisibleBy.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "by int", 4 | "schema": {"divisibleBy": 2}, 5 | "tests": [ 6 | { 7 | "description": "int by int", 8 | "data": 10, 9 | "valid": true 10 | }, 11 | { 12 | "description": "int by int fail", 13 | "data": 7, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "foo", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "by number", 25 | "schema": {"divisibleBy": 1.5}, 26 | "tests": [ 27 | { 28 | "description": "zero is divisible by anything (except 0)", 29 | "data": 0, 30 | "valid": true 31 | }, 32 | { 33 | "description": "4.5 is divisible by 1.5", 34 | "data": 4.5, 35 | "valid": true 36 | }, 37 | { 38 | "description": "35 is not divisible by 1.5", 39 | "data": 35, 40 | "valid": false 41 | } 42 | ] 43 | }, 44 | { 45 | "description": "by small number", 46 | "schema": {"divisibleBy": 0.0001}, 47 | "tests": [ 48 | { 49 | "description": "0.0075 is divisible by 0.0001", 50 | "data": 0.0075, 51 | "valid": true 52 | }, 53 | { 54 | "description": "0.00751 is not divisible by 0.0001", 55 | "data": 0.00751, 56 | "valid": false 57 | } 58 | ] 59 | } 60 | ] 61 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/enum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "simple enum validation", 4 | "schema": {"enum": [1, 2, 3]}, 5 | "tests": [ 6 | { 7 | "description": "one of the enum is valid", 8 | "data": 1, 9 | "valid": true 10 | }, 11 | { 12 | "description": "something else is invalid", 13 | "data": 4, 14 | "valid": false 15 | } 16 | ] 17 | }, 18 | { 19 | "description": "heterogeneous enum validation", 20 | "schema": {"enum": [6, "foo", [], true, {"foo": 12}]}, 21 | "tests": [ 22 | { 23 | "description": "one of the enum is valid", 24 | "data": [], 25 | "valid": true 26 | }, 27 | { 28 | "description": "something else is invalid", 29 | "data": null, 30 | "valid": false 31 | }, 32 | { 33 | "description": "objects are deep compared", 34 | "data": {"foo": false}, 35 | "valid": false 36 | } 37 | ] 38 | }, 39 | { 40 | "description": "enums in properties", 41 | "schema": { 42 | "type":"object", 43 | "properties": { 44 | "foo": {"enum":["foo"]}, 45 | "bar": {"enum":["bar"], "required":true} 46 | } 47 | }, 48 | "tests": [ 49 | { 50 | "description": "both properties are valid", 51 | "data": {"foo":"foo", "bar":"bar"}, 52 | "valid": true 53 | }, 54 | { 55 | "description": "missing optional property is valid", 56 | "data": {"bar":"bar"}, 57 | "valid": true 58 | }, 59 | { 60 | "description": "missing required property is invalid", 61 | "data": {"foo":"foo"}, 62 | "valid": false 63 | }, 64 | { 65 | "description": "missing all properties is invalid", 66 | "data": {}, 67 | "valid": false 68 | } 69 | ] 70 | } 71 | ] 72 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/extends.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "extends", 4 | "schema": { 5 | "properties": {"bar": {"type": "integer", "required": true}}, 6 | "extends": { 7 | "properties": { 8 | "foo": {"type": "string", "required": true} 9 | } 10 | } 11 | }, 12 | "tests": [ 13 | { 14 | "description": "extends", 15 | "data": {"foo": "baz", "bar": 2}, 16 | "valid": true 17 | }, 18 | { 19 | "description": "mismatch extends", 20 | "data": {"foo": "baz"}, 21 | "valid": false 22 | }, 23 | { 24 | "description": "mismatch extended", 25 | "data": {"bar": 2}, 26 | "valid": false 27 | }, 28 | { 29 | "description": "wrong type", 30 | "data": {"foo": "baz", "bar": "quux"}, 31 | "valid": false 32 | } 33 | ] 34 | }, 35 | { 36 | "description": "multiple extends", 37 | "schema": { 38 | "properties": {"bar": {"type": "integer", "required": true}}, 39 | "extends" : [ 40 | { 41 | "properties": { 42 | "foo": {"type": "string", "required": true} 43 | } 44 | }, 45 | { 46 | "properties": { 47 | "baz": {"type": "null", "required": true} 48 | } 49 | } 50 | ] 51 | }, 52 | "tests": [ 53 | { 54 | "description": "valid", 55 | "data": {"foo": "quux", "bar": 2, "baz": null}, 56 | "valid": true 57 | }, 58 | { 59 | "description": "mismatch first extends", 60 | "data": {"bar": 2, "baz": null}, 61 | "valid": false 62 | }, 63 | { 64 | "description": "mismatch second extends", 65 | "data": {"foo": "quux", "bar": 2}, 66 | "valid": false 67 | }, 68 | { 69 | "description": "mismatch both", 70 | "data": {"bar": 2}, 71 | "valid": false 72 | } 73 | ] 74 | }, 75 | { 76 | "description": "extends simple types", 77 | "schema": { 78 | "minimum": 20, 79 | "extends": {"maximum": 30} 80 | }, 81 | "tests": [ 82 | { 83 | "description": "valid", 84 | "data": 25, 85 | "valid": true 86 | }, 87 | { 88 | "description": "mismatch extends", 89 | "data": 35, 90 | "valid": false 91 | } 92 | ] 93 | } 94 | ] 95 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/items.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "a schema given for items", 4 | "schema": { 5 | "items": {"type": "integer"} 6 | }, 7 | "tests": [ 8 | { 9 | "description": "valid items", 10 | "data": [ 1, 2, 3 ], 11 | "valid": true 12 | }, 13 | { 14 | "description": "wrong type of items", 15 | "data": [1, "x"], 16 | "valid": false 17 | }, 18 | { 19 | "description": "ignores non-arrays", 20 | "data": {"foo" : "bar"}, 21 | "valid": true 22 | } 23 | ] 24 | }, 25 | { 26 | "description": "an array of schemas for items", 27 | "schema": { 28 | "items": [ 29 | {"type": "integer"}, 30 | {"type": "string"} 31 | ] 32 | }, 33 | "tests": [ 34 | { 35 | "description": "correct types", 36 | "data": [ 1, "foo" ], 37 | "valid": true 38 | }, 39 | { 40 | "description": "wrong types", 41 | "data": [ "foo", 1 ], 42 | "valid": false 43 | } 44 | ] 45 | } 46 | ] 47 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/maxItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maxItems validation", 4 | "schema": {"maxItems": 2}, 5 | "tests": [ 6 | { 7 | "description": "shorter is valid", 8 | "data": [1], 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": [1, 2], 14 | "valid": true 15 | }, 16 | { 17 | "description": "too long is invalid", 18 | "data": [1, 2, 3], 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-arrays", 23 | "data": "foobar", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/maxLength.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maxLength validation", 4 | "schema": {"maxLength": 2}, 5 | "tests": [ 6 | { 7 | "description": "shorter is valid", 8 | "data": "f", 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": "fo", 14 | "valid": true 15 | }, 16 | { 17 | "description": "too long is invalid", 18 | "data": "foo", 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-strings", 23 | "data": 10, 24 | "valid": true 25 | }, 26 | { 27 | "description": "two supplementary Unicode code points is long enough", 28 | "data": "\uD83D\uDCA9\uD83D\uDCA9", 29 | "valid": true 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/maximum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maximum validation", 4 | "schema": {"maximum": 3.0}, 5 | "tests": [ 6 | { 7 | "description": "below the maximum is valid", 8 | "data": 2.6, 9 | "valid": true 10 | }, 11 | { 12 | "description": "above the maximum is invalid", 13 | "data": 3.5, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "x", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "exclusiveMaximum validation", 25 | "schema": { 26 | "maximum": 3.0, 27 | "exclusiveMaximum": true 28 | }, 29 | "tests": [ 30 | { 31 | "description": "below the maximum is still valid", 32 | "data": 2.2, 33 | "valid": true 34 | }, 35 | { 36 | "description": "boundary point is invalid", 37 | "data": 3.0, 38 | "valid": false 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/minItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minItems validation", 4 | "schema": {"minItems": 1}, 5 | "tests": [ 6 | { 7 | "description": "longer is valid", 8 | "data": [1, 2], 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": [1], 14 | "valid": true 15 | }, 16 | { 17 | "description": "too short is invalid", 18 | "data": [], 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-arrays", 23 | "data": "", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/minLength.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minLength validation", 4 | "schema": {"minLength": 2}, 5 | "tests": [ 6 | { 7 | "description": "longer is valid", 8 | "data": "foo", 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": "fo", 14 | "valid": true 15 | }, 16 | { 17 | "description": "too short is invalid", 18 | "data": "f", 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-strings", 23 | "data": 1, 24 | "valid": true 25 | }, 26 | { 27 | "description": "one supplementary Unicode code point is not long enough", 28 | "data": "\uD83D\uDCA9", 29 | "valid": false 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/minimum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minimum validation", 4 | "schema": {"minimum": 1.1}, 5 | "tests": [ 6 | { 7 | "description": "above the minimum is valid", 8 | "data": 2.6, 9 | "valid": true 10 | }, 11 | { 12 | "description": "below the minimum is invalid", 13 | "data": 0.6, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "x", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "exclusiveMinimum validation", 25 | "schema": { 26 | "minimum": 1.1, 27 | "exclusiveMinimum": true 28 | }, 29 | "tests": [ 30 | { 31 | "description": "above the minimum is still valid", 32 | "data": 1.2, 33 | "valid": true 34 | }, 35 | { 36 | "description": "boundary point is invalid", 37 | "data": 1.1, 38 | "valid": false 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/optional/jsregex.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "ECMA 262 regex dialect recognition", 4 | "schema": { "format": "regex" }, 5 | "tests": [ 6 | { 7 | "description": "[^] is a valid regex", 8 | "data": "[^]", 9 | "valid": true 10 | }, 11 | { 12 | "description": "ECMA 262 has no support for lookbehind", 13 | "data": "(?<=foo)bar", 14 | "valid": false 15 | } 16 | ] 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "some languages do not distinguish between different types of numeric value", 4 | "schema": { 5 | "type": "integer" 6 | }, 7 | "tests": [ 8 | { 9 | "description": "a float is not an integer even without fractional part", 10 | "data": 1.0, 11 | "valid": false 12 | } 13 | ] 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/pattern.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pattern validation", 4 | "schema": {"pattern": "^a*$"}, 5 | "tests": [ 6 | { 7 | "description": "a matching pattern is valid", 8 | "data": "aaa", 9 | "valid": true 10 | }, 11 | { 12 | "description": "a non-matching pattern is invalid", 13 | "data": "abc", 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-strings", 18 | "data": true, 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "pattern is not anchored", 25 | "schema": {"pattern": "a+"}, 26 | "tests": [ 27 | { 28 | "description": "matches a substring", 29 | "data": "xxaayy", 30 | "valid": true 31 | } 32 | ] 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/properties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "object properties validation", 4 | "schema": { 5 | "properties": { 6 | "foo": {"type": "integer"}, 7 | "bar": {"type": "string"} 8 | } 9 | }, 10 | "tests": [ 11 | { 12 | "description": "both properties present and valid is valid", 13 | "data": {"foo": 1, "bar": "baz"}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "one property invalid is invalid", 18 | "data": {"foo": 1, "bar": {}}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "both properties invalid is invalid", 23 | "data": {"foo": [], "bar": {}}, 24 | "valid": false 25 | }, 26 | { 27 | "description": "doesn't invalidate other properties", 28 | "data": {"quux": []}, 29 | "valid": true 30 | }, 31 | { 32 | "description": "ignores non-objects", 33 | "data": [], 34 | "valid": true 35 | } 36 | ] 37 | }, 38 | { 39 | "description": 40 | "properties, patternProperties, additionalProperties interaction", 41 | "schema": { 42 | "properties": { 43 | "foo": {"type": "array", "maxItems": 3}, 44 | "bar": {"type": "array"} 45 | }, 46 | "patternProperties": {"f.o": {"minItems": 2}}, 47 | "additionalProperties": {"type": "integer"} 48 | }, 49 | "tests": [ 50 | { 51 | "description": "property validates property", 52 | "data": {"foo": [1, 2]}, 53 | "valid": true 54 | }, 55 | { 56 | "description": "property invalidates property", 57 | "data": {"foo": [1, 2, 3, 4]}, 58 | "valid": false 59 | }, 60 | { 61 | "description": "patternProperty invalidates property", 62 | "data": {"foo": []}, 63 | "valid": false 64 | }, 65 | { 66 | "description": "patternProperty validates nonproperty", 67 | "data": {"fxo": [1, 2]}, 68 | "valid": true 69 | }, 70 | { 71 | "description": "patternProperty invalidates nonproperty", 72 | "data": {"fxo": []}, 73 | "valid": false 74 | }, 75 | { 76 | "description": "additionalProperty ignores property", 77 | "data": {"bar": []}, 78 | "valid": true 79 | }, 80 | { 81 | "description": "additionalProperty validates others", 82 | "data": {"quux": 3}, 83 | "valid": true 84 | }, 85 | { 86 | "description": "additionalProperty invalidates others", 87 | "data": {"quux": "foo"}, 88 | "valid": false 89 | } 90 | ] 91 | } 92 | ] 93 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/refRemote.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "remote ref", 4 | "schema": {"$ref": "http://localhost:1234/integer.json"}, 5 | "tests": [ 6 | { 7 | "description": "remote ref valid", 8 | "data": 1, 9 | "valid": true 10 | }, 11 | { 12 | "description": "remote ref invalid", 13 | "data": "a", 14 | "valid": false 15 | } 16 | ] 17 | }, 18 | { 19 | "description": "fragment within remote ref", 20 | "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, 21 | "tests": [ 22 | { 23 | "description": "remote fragment valid", 24 | "data": 1, 25 | "valid": true 26 | }, 27 | { 28 | "description": "remote fragment invalid", 29 | "data": "a", 30 | "valid": false 31 | } 32 | ] 33 | }, 34 | { 35 | "description": "ref within remote ref", 36 | "schema": { 37 | "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" 38 | }, 39 | "tests": [ 40 | { 41 | "description": "ref within ref valid", 42 | "data": 1, 43 | "valid": true 44 | }, 45 | { 46 | "description": "ref within ref invalid", 47 | "data": "a", 48 | "valid": false 49 | } 50 | ] 51 | }, 52 | { 53 | "description": "change resolution scope", 54 | "schema": { 55 | "id": "http://localhost:1234/", 56 | "items": { 57 | "id": "folder/", 58 | "items": {"$ref": "folderInteger.json"} 59 | } 60 | }, 61 | "tests": [ 62 | { 63 | "description": "changed scope ref valid", 64 | "data": [[1]], 65 | "valid": true 66 | }, 67 | { 68 | "description": "changed scope ref invalid", 69 | "data": [["a"]], 70 | "valid": false 71 | } 72 | ] 73 | } 74 | ] 75 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/required.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "required validation", 4 | "schema": { 5 | "properties": { 6 | "foo": {"required" : true}, 7 | "bar": {} 8 | } 9 | }, 10 | "tests": [ 11 | { 12 | "description": "present required property is valid", 13 | "data": {"foo": 1}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "non-present required property is invalid", 18 | "data": {"bar": 1}, 19 | "valid": false 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "required default validation", 25 | "schema": { 26 | "properties": { 27 | "foo": {} 28 | } 29 | }, 30 | "tests": [ 31 | { 32 | "description": "not required by default", 33 | "data": {}, 34 | "valid": true 35 | } 36 | ] 37 | }, 38 | { 39 | "description": "required explicitly false validation", 40 | "schema": { 41 | "properties": { 42 | "foo": {"required": false} 43 | } 44 | }, 45 | "tests": [ 46 | { 47 | "description": "not required if required is false", 48 | "data": {}, 49 | "valid": true 50 | } 51 | ] 52 | } 53 | ] 54 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft3/uniqueItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "uniqueItems validation", 4 | "schema": {"uniqueItems": true}, 5 | "tests": [ 6 | { 7 | "description": "unique array of integers is valid", 8 | "data": [1, 2], 9 | "valid": true 10 | }, 11 | { 12 | "description": "non-unique array of integers is invalid", 13 | "data": [1, 1], 14 | "valid": false 15 | }, 16 | { 17 | "description": "numbers are unique if mathematically unequal", 18 | "data": [1.0, 1.00, 1], 19 | "valid": false 20 | }, 21 | { 22 | "description": "unique array of objects is valid", 23 | "data": [{"foo": "bar"}, {"foo": "baz"}], 24 | "valid": true 25 | }, 26 | { 27 | "description": "non-unique array of objects is invalid", 28 | "data": [{"foo": "bar"}, {"foo": "bar"}], 29 | "valid": false 30 | }, 31 | { 32 | "description": "unique array of nested objects is valid", 33 | "data": [ 34 | {"foo": {"bar" : {"baz" : true}}}, 35 | {"foo": {"bar" : {"baz" : false}}} 36 | ], 37 | "valid": true 38 | }, 39 | { 40 | "description": "non-unique array of nested objects is invalid", 41 | "data": [ 42 | {"foo": {"bar" : {"baz" : true}}}, 43 | {"foo": {"bar" : {"baz" : true}}} 44 | ], 45 | "valid": false 46 | }, 47 | { 48 | "description": "unique array of arrays is valid", 49 | "data": [["foo"], ["bar"]], 50 | "valid": true 51 | }, 52 | { 53 | "description": "non-unique array of arrays is invalid", 54 | "data": [["foo"], ["foo"]], 55 | "valid": false 56 | }, 57 | { 58 | "description": "1 and true are unique", 59 | "data": [1, true], 60 | "valid": true 61 | }, 62 | { 63 | "description": "0 and false are unique", 64 | "data": [0, false], 65 | "valid": true 66 | }, 67 | { 68 | "description": "unique heterogeneous types are valid", 69 | "data": [{}, [1], true, null, 1], 70 | "valid": true 71 | }, 72 | { 73 | "description": "non-unique heterogeneous types are invalid", 74 | "data": [{}, [1], true, null, {}, 1], 75 | "valid": false 76 | } 77 | ] 78 | } 79 | ] 80 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/additionalItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "additionalItems as schema", 4 | "schema": { 5 | "items": [{}], 6 | "additionalItems": {"type": "integer"} 7 | }, 8 | "tests": [ 9 | { 10 | "description": "additional items match schema", 11 | "data": [ null, 2, 3, 4 ], 12 | "valid": true 13 | }, 14 | { 15 | "description": "additional items do not match schema", 16 | "data": [ null, 2, 3, "foo" ], 17 | "valid": false 18 | } 19 | ] 20 | }, 21 | { 22 | "description": "items is schema, no additionalItems", 23 | "schema": { 24 | "items": {}, 25 | "additionalItems": false 26 | }, 27 | "tests": [ 28 | { 29 | "description": "all items match schema", 30 | "data": [ 1, 2, 3, 4, 5 ], 31 | "valid": true 32 | } 33 | ] 34 | }, 35 | { 36 | "description": "array of items with no additionalItems", 37 | "schema": { 38 | "items": [{}, {}, {}], 39 | "additionalItems": false 40 | }, 41 | "tests": [ 42 | { 43 | "description": "no additional items present", 44 | "data": [ 1, 2, 3 ], 45 | "valid": true 46 | }, 47 | { 48 | "description": "additional items are not permitted", 49 | "data": [ 1, 2, 3, 4 ], 50 | "valid": false 51 | } 52 | ] 53 | }, 54 | { 55 | "description": "additionalItems as false without items", 56 | "schema": {"additionalItems": false}, 57 | "tests": [ 58 | { 59 | "description": 60 | "items defaults to empty schema so everything is valid", 61 | "data": [ 1, 2, 3, 4, 5 ], 62 | "valid": true 63 | }, 64 | { 65 | "description": "ignores non-arrays", 66 | "data": {"foo" : "bar"}, 67 | "valid": true 68 | } 69 | ] 70 | }, 71 | { 72 | "description": "additionalItems are allowed by default", 73 | "schema": {"items": [{"type": "integer"}]}, 74 | "tests": [ 75 | { 76 | "description": "only the first item is validated", 77 | "data": [1, "foo", false], 78 | "valid": true 79 | } 80 | ] 81 | } 82 | ] 83 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/additionalProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": 4 | "additionalProperties being false does not allow other properties", 5 | "schema": { 6 | "properties": {"foo": {}, "bar": {}}, 7 | "patternProperties": { "^v": {} }, 8 | "additionalProperties": false 9 | }, 10 | "tests": [ 11 | { 12 | "description": "no additional properties is valid", 13 | "data": {"foo": 1}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "an additional property is invalid", 18 | "data": {"foo" : 1, "bar" : 2, "quux" : "boom"}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-objects", 23 | "data": [1, 2, 3], 24 | "valid": true 25 | }, 26 | { 27 | "description": "patternProperties are not additional properties", 28 | "data": {"foo":1, "vroom": 2}, 29 | "valid": true 30 | } 31 | ] 32 | }, 33 | { 34 | "description": 35 | "additionalProperties allows a schema which should validate", 36 | "schema": { 37 | "properties": {"foo": {}, "bar": {}}, 38 | "additionalProperties": {"type": "boolean"} 39 | }, 40 | "tests": [ 41 | { 42 | "description": "no additional properties is valid", 43 | "data": {"foo": 1}, 44 | "valid": true 45 | }, 46 | { 47 | "description": "an additional valid property is valid", 48 | "data": {"foo" : 1, "bar" : 2, "quux" : true}, 49 | "valid": true 50 | }, 51 | { 52 | "description": "an additional invalid property is invalid", 53 | "data": {"foo" : 1, "bar" : 2, "quux" : 12}, 54 | "valid": false 55 | } 56 | ] 57 | }, 58 | { 59 | "description": 60 | "additionalProperties can exist by itself", 61 | "schema": { 62 | "additionalProperties": {"type": "boolean"} 63 | }, 64 | "tests": [ 65 | { 66 | "description": "an additional valid property is valid", 67 | "data": {"foo" : true}, 68 | "valid": true 69 | }, 70 | { 71 | "description": "an additional invalid property is invalid", 72 | "data": {"foo" : 1}, 73 | "valid": false 74 | } 75 | ] 76 | }, 77 | { 78 | "description": "additionalProperties are allowed by default", 79 | "schema": {"properties": {"foo": {}, "bar": {}}}, 80 | "tests": [ 81 | { 82 | "description": "additional properties are allowed", 83 | "data": {"foo": 1, "bar": 2, "quux": true}, 84 | "valid": true 85 | } 86 | ] 87 | } 88 | ] 89 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/anyOf.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "anyOf", 4 | "schema": { 5 | "anyOf": [ 6 | { 7 | "type": "integer" 8 | }, 9 | { 10 | "minimum": 2 11 | } 12 | ] 13 | }, 14 | "tests": [ 15 | { 16 | "description": "first anyOf valid", 17 | "data": 1, 18 | "valid": true 19 | }, 20 | { 21 | "description": "second anyOf valid", 22 | "data": 2.5, 23 | "valid": true 24 | }, 25 | { 26 | "description": "both anyOf valid", 27 | "data": 3, 28 | "valid": true 29 | }, 30 | { 31 | "description": "neither anyOf valid", 32 | "data": 1.5, 33 | "valid": false 34 | } 35 | ] 36 | }, 37 | { 38 | "description": "anyOf with base schema", 39 | "schema": { 40 | "type": "string", 41 | "anyOf" : [ 42 | { 43 | "maxLength": 2 44 | }, 45 | { 46 | "minLength": 4 47 | } 48 | ] 49 | }, 50 | "tests": [ 51 | { 52 | "description": "mismatch base schema", 53 | "data": 3, 54 | "valid": false 55 | }, 56 | { 57 | "description": "one anyOf valid", 58 | "data": "foobar", 59 | "valid": true 60 | }, 61 | { 62 | "description": "both anyOf invalid", 63 | "data": "foo", 64 | "valid": false 65 | } 66 | ] 67 | } 68 | ] 69 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/default.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "invalid type for default", 4 | "schema": { 5 | "properties": { 6 | "foo": { 7 | "type": "integer", 8 | "default": [] 9 | } 10 | } 11 | }, 12 | "tests": [ 13 | { 14 | "description": "valid when property is specified", 15 | "data": {"foo": 13}, 16 | "valid": true 17 | }, 18 | { 19 | "description": "still valid when the invalid default is used", 20 | "data": {}, 21 | "valid": true 22 | } 23 | ] 24 | }, 25 | { 26 | "description": "invalid string value for default", 27 | "schema": { 28 | "properties": { 29 | "bar": { 30 | "type": "string", 31 | "minLength": 4, 32 | "default": "bad" 33 | } 34 | } 35 | }, 36 | "tests": [ 37 | { 38 | "description": "valid when property is specified", 39 | "data": {"bar": "good"}, 40 | "valid": true 41 | }, 42 | { 43 | "description": "still valid when the invalid default is used", 44 | "data": {}, 45 | "valid": true 46 | } 47 | ] 48 | } 49 | ] 50 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/definitions.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "valid definition", 4 | "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, 5 | "tests": [ 6 | { 7 | "description": "valid definition schema", 8 | "data": { 9 | "definitions": { 10 | "foo": {"type": "integer"} 11 | } 12 | }, 13 | "valid": true 14 | } 15 | ] 16 | }, 17 | { 18 | "description": "invalid definition", 19 | "schema": {"$ref": "http://json-schema.org/draft-04/schema#"}, 20 | "tests": [ 21 | { 22 | "description": "invalid definition schema", 23 | "data": { 24 | "definitions": { 25 | "foo": {"type": 1} 26 | } 27 | }, 28 | "valid": false 29 | } 30 | ] 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/enum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "simple enum validation", 4 | "schema": {"enum": [1, 2, 3]}, 5 | "tests": [ 6 | { 7 | "description": "one of the enum is valid", 8 | "data": 1, 9 | "valid": true 10 | }, 11 | { 12 | "description": "something else is invalid", 13 | "data": 4, 14 | "valid": false 15 | } 16 | ] 17 | }, 18 | { 19 | "description": "heterogeneous enum validation", 20 | "schema": {"enum": [6, "foo", [], true, {"foo": 12}]}, 21 | "tests": [ 22 | { 23 | "description": "one of the enum is valid", 24 | "data": [], 25 | "valid": true 26 | }, 27 | { 28 | "description": "something else is invalid", 29 | "data": null, 30 | "valid": false 31 | }, 32 | { 33 | "description": "objects are deep compared", 34 | "data": {"foo": false}, 35 | "valid": false 36 | } 37 | ] 38 | }, 39 | { 40 | "description": "enums in properties", 41 | "schema": { 42 | "type":"object", 43 | "properties": { 44 | "foo": {"enum":["foo"]}, 45 | "bar": {"enum":["bar"]} 46 | }, 47 | "required": ["bar"] 48 | }, 49 | "tests": [ 50 | { 51 | "description": "both properties are valid", 52 | "data": {"foo":"foo", "bar":"bar"}, 53 | "valid": true 54 | }, 55 | { 56 | "description": "missing optional property is valid", 57 | "data": {"bar":"bar"}, 58 | "valid": true 59 | }, 60 | { 61 | "description": "missing required property is invalid", 62 | "data": {"foo":"foo"}, 63 | "valid": false 64 | }, 65 | { 66 | "description": "missing all properties is invalid", 67 | "data": {}, 68 | "valid": false 69 | } 70 | ] 71 | } 72 | ] 73 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/items.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "a schema given for items", 4 | "schema": { 5 | "items": {"type": "integer"} 6 | }, 7 | "tests": [ 8 | { 9 | "description": "valid items", 10 | "data": [ 1, 2, 3 ], 11 | "valid": true 12 | }, 13 | { 14 | "description": "wrong type of items", 15 | "data": [1, "x"], 16 | "valid": false 17 | }, 18 | { 19 | "description": "ignores non-arrays", 20 | "data": {"foo" : "bar"}, 21 | "valid": true 22 | } 23 | ] 24 | }, 25 | { 26 | "description": "an array of schemas for items", 27 | "schema": { 28 | "items": [ 29 | {"type": "integer"}, 30 | {"type": "string"} 31 | ] 32 | }, 33 | "tests": [ 34 | { 35 | "description": "correct types", 36 | "data": [ 1, "foo" ], 37 | "valid": true 38 | }, 39 | { 40 | "description": "wrong types", 41 | "data": [ "foo", 1 ], 42 | "valid": false 43 | } 44 | ] 45 | } 46 | ] 47 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/maxItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maxItems validation", 4 | "schema": {"maxItems": 2}, 5 | "tests": [ 6 | { 7 | "description": "shorter is valid", 8 | "data": [1], 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": [1, 2], 14 | "valid": true 15 | }, 16 | { 17 | "description": "too long is invalid", 18 | "data": [1, 2, 3], 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-arrays", 23 | "data": "foobar", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/maxLength.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maxLength validation", 4 | "schema": {"maxLength": 2}, 5 | "tests": [ 6 | { 7 | "description": "shorter is valid", 8 | "data": "f", 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": "fo", 14 | "valid": true 15 | }, 16 | { 17 | "description": "too long is invalid", 18 | "data": "foo", 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-strings", 23 | "data": 100, 24 | "valid": true 25 | }, 26 | { 27 | "description": "two supplementary Unicode code points is long enough", 28 | "data": "\uD83D\uDCA9\uD83D\uDCA9", 29 | "valid": true 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/maxProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maxProperties validation", 4 | "schema": {"maxProperties": 2}, 5 | "tests": [ 6 | { 7 | "description": "shorter is valid", 8 | "data": {"foo": 1}, 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": {"foo": 1, "bar": 2}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "too long is invalid", 18 | "data": {"foo": 1, "bar": 2, "baz": 3}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-objects", 23 | "data": "foobar", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/maximum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "maximum validation", 4 | "schema": {"maximum": 3.0}, 5 | "tests": [ 6 | { 7 | "description": "below the maximum is valid", 8 | "data": 2.6, 9 | "valid": true 10 | }, 11 | { 12 | "description": "above the maximum is invalid", 13 | "data": 3.5, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "x", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "exclusiveMaximum validation", 25 | "schema": { 26 | "maximum": 3.0, 27 | "exclusiveMaximum": true 28 | }, 29 | "tests": [ 30 | { 31 | "description": "below the maximum is still valid", 32 | "data": 2.2, 33 | "valid": true 34 | }, 35 | { 36 | "description": "boundary point is invalid", 37 | "data": 3.0, 38 | "valid": false 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/minItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minItems validation", 4 | "schema": {"minItems": 1}, 5 | "tests": [ 6 | { 7 | "description": "longer is valid", 8 | "data": [1, 2], 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": [1], 14 | "valid": true 15 | }, 16 | { 17 | "description": "too short is invalid", 18 | "data": [], 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-arrays", 23 | "data": "", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/minLength.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minLength validation", 4 | "schema": {"minLength": 2}, 5 | "tests": [ 6 | { 7 | "description": "longer is valid", 8 | "data": "foo", 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": "fo", 14 | "valid": true 15 | }, 16 | { 17 | "description": "too short is invalid", 18 | "data": "f", 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-strings", 23 | "data": 1, 24 | "valid": true 25 | }, 26 | { 27 | "description": "one supplementary Unicode code point is not long enough", 28 | "data": "\uD83D\uDCA9", 29 | "valid": false 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/minProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minProperties validation", 4 | "schema": {"minProperties": 1}, 5 | "tests": [ 6 | { 7 | "description": "longer is valid", 8 | "data": {"foo": 1, "bar": 2}, 9 | "valid": true 10 | }, 11 | { 12 | "description": "exact length is valid", 13 | "data": {"foo": 1}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "too short is invalid", 18 | "data": {}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "ignores non-objects", 23 | "data": "", 24 | "valid": true 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/minimum.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "minimum validation", 4 | "schema": {"minimum": 1.1}, 5 | "tests": [ 6 | { 7 | "description": "above the minimum is valid", 8 | "data": 2.6, 9 | "valid": true 10 | }, 11 | { 12 | "description": "below the minimum is invalid", 13 | "data": 0.6, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "x", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "exclusiveMinimum validation", 25 | "schema": { 26 | "minimum": 1.1, 27 | "exclusiveMinimum": true 28 | }, 29 | "tests": [ 30 | { 31 | "description": "above the minimum is still valid", 32 | "data": 1.2, 33 | "valid": true 34 | }, 35 | { 36 | "description": "boundary point is invalid", 37 | "data": 1.1, 38 | "valid": false 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/multipleOf.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "by int", 4 | "schema": {"multipleOf": 2}, 5 | "tests": [ 6 | { 7 | "description": "int by int", 8 | "data": 10, 9 | "valid": true 10 | }, 11 | { 12 | "description": "int by int fail", 13 | "data": 7, 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-numbers", 18 | "data": "foo", 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "by number", 25 | "schema": {"multipleOf": 1.5}, 26 | "tests": [ 27 | { 28 | "description": "zero is multiple of anything", 29 | "data": 0, 30 | "valid": true 31 | }, 32 | { 33 | "description": "4.5 is multiple of 1.5", 34 | "data": 4.5, 35 | "valid": true 36 | }, 37 | { 38 | "description": "35 is not multiple of 1.5", 39 | "data": 35, 40 | "valid": false 41 | } 42 | ] 43 | }, 44 | { 45 | "description": "by small number", 46 | "schema": {"multipleOf": 0.0001}, 47 | "tests": [ 48 | { 49 | "description": "0.0075 is multiple of 0.0001", 50 | "data": 0.0075, 51 | "valid": true 52 | }, 53 | { 54 | "description": "0.00751 is not multiple of 0.0001", 55 | "data": 0.00751, 56 | "valid": false 57 | } 58 | ] 59 | } 60 | ] 61 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/not.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "not", 4 | "schema": { 5 | "not": {"type": "integer"} 6 | }, 7 | "tests": [ 8 | { 9 | "description": "allowed", 10 | "data": "foo", 11 | "valid": true 12 | }, 13 | { 14 | "description": "disallowed", 15 | "data": 1, 16 | "valid": false 17 | } 18 | ] 19 | }, 20 | { 21 | "description": "not multiple types", 22 | "schema": { 23 | "not": {"type": ["integer", "boolean"]} 24 | }, 25 | "tests": [ 26 | { 27 | "description": "valid", 28 | "data": "foo", 29 | "valid": true 30 | }, 31 | { 32 | "description": "mismatch", 33 | "data": 1, 34 | "valid": false 35 | }, 36 | { 37 | "description": "other mismatch", 38 | "data": true, 39 | "valid": false 40 | } 41 | ] 42 | }, 43 | { 44 | "description": "not more complex schema", 45 | "schema": { 46 | "not": { 47 | "type": "object", 48 | "properties": { 49 | "foo": { 50 | "type": "string" 51 | } 52 | } 53 | } 54 | }, 55 | "tests": [ 56 | { 57 | "description": "match", 58 | "data": 1, 59 | "valid": true 60 | }, 61 | { 62 | "description": "other match", 63 | "data": {"foo": 1}, 64 | "valid": true 65 | }, 66 | { 67 | "description": "mismatch", 68 | "data": {"foo": "bar"}, 69 | "valid": false 70 | } 71 | ] 72 | }, 73 | { 74 | "description": "forbidden property", 75 | "schema": { 76 | "properties": { 77 | "foo": { 78 | "not": {} 79 | } 80 | } 81 | }, 82 | "tests": [ 83 | { 84 | "description": "property present", 85 | "data": {"foo": 1, "bar": 2}, 86 | "valid": false 87 | }, 88 | { 89 | "description": "property absent", 90 | "data": {"bar": 1, "baz": 2}, 91 | "valid": true 92 | } 93 | ] 94 | } 95 | 96 | ] 97 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/oneOf.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "oneOf", 4 | "schema": { 5 | "oneOf": [ 6 | { 7 | "type": "integer" 8 | }, 9 | { 10 | "minimum": 2 11 | } 12 | ] 13 | }, 14 | "tests": [ 15 | { 16 | "description": "first oneOf valid", 17 | "data": 1, 18 | "valid": true 19 | }, 20 | { 21 | "description": "second oneOf valid", 22 | "data": 2.5, 23 | "valid": true 24 | }, 25 | { 26 | "description": "both oneOf valid", 27 | "data": 3, 28 | "valid": false 29 | }, 30 | { 31 | "description": "neither oneOf valid", 32 | "data": 1.5, 33 | "valid": false 34 | } 35 | ] 36 | }, 37 | { 38 | "description": "oneOf with base schema", 39 | "schema": { 40 | "type": "string", 41 | "oneOf" : [ 42 | { 43 | "minLength": 2 44 | }, 45 | { 46 | "maxLength": 4 47 | } 48 | ] 49 | }, 50 | "tests": [ 51 | { 52 | "description": "mismatch base schema", 53 | "data": 3, 54 | "valid": false 55 | }, 56 | { 57 | "description": "one oneOf valid", 58 | "data": "foobar", 59 | "valid": true 60 | }, 61 | { 62 | "description": "both oneOf valid", 63 | "data": "foo", 64 | "valid": false 65 | } 66 | ] 67 | } 68 | ] 69 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "some languages do not distinguish between different types of numeric value", 4 | "schema": { 5 | "type": "integer" 6 | }, 7 | "tests": [ 8 | { 9 | "description": "a float is not an integer even without fractional part", 10 | "data": 1.0, 11 | "valid": false 12 | } 13 | ] 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/pattern.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pattern validation", 4 | "schema": {"pattern": "^a*$"}, 5 | "tests": [ 6 | { 7 | "description": "a matching pattern is valid", 8 | "data": "aaa", 9 | "valid": true 10 | }, 11 | { 12 | "description": "a non-matching pattern is invalid", 13 | "data": "abc", 14 | "valid": false 15 | }, 16 | { 17 | "description": "ignores non-strings", 18 | "data": true, 19 | "valid": true 20 | } 21 | ] 22 | }, 23 | { 24 | "description": "pattern is not anchored", 25 | "schema": {"pattern": "a+"}, 26 | "tests": [ 27 | { 28 | "description": "matches a substring", 29 | "data": "xxaayy", 30 | "valid": true 31 | } 32 | ] 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/properties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "object properties validation", 4 | "schema": { 5 | "properties": { 6 | "foo": {"type": "integer"}, 7 | "bar": {"type": "string"} 8 | } 9 | }, 10 | "tests": [ 11 | { 12 | "description": "both properties present and valid is valid", 13 | "data": {"foo": 1, "bar": "baz"}, 14 | "valid": true 15 | }, 16 | { 17 | "description": "one property invalid is invalid", 18 | "data": {"foo": 1, "bar": {}}, 19 | "valid": false 20 | }, 21 | { 22 | "description": "both properties invalid is invalid", 23 | "data": {"foo": [], "bar": {}}, 24 | "valid": false 25 | }, 26 | { 27 | "description": "doesn't invalidate other properties", 28 | "data": {"quux": []}, 29 | "valid": true 30 | }, 31 | { 32 | "description": "ignores non-objects", 33 | "data": [], 34 | "valid": true 35 | } 36 | ] 37 | }, 38 | { 39 | "description": 40 | "properties, patternProperties, additionalProperties interaction", 41 | "schema": { 42 | "properties": { 43 | "foo": {"type": "array", "maxItems": 3}, 44 | "bar": {"type": "array"} 45 | }, 46 | "patternProperties": {"f.o": {"minItems": 2}}, 47 | "additionalProperties": {"type": "integer"} 48 | }, 49 | "tests": [ 50 | { 51 | "description": "property validates property", 52 | "data": {"foo": [1, 2]}, 53 | "valid": true 54 | }, 55 | { 56 | "description": "property invalidates property", 57 | "data": {"foo": [1, 2, 3, 4]}, 58 | "valid": false 59 | }, 60 | { 61 | "description": "patternProperty invalidates property", 62 | "data": {"foo": []}, 63 | "valid": false 64 | }, 65 | { 66 | "description": "patternProperty validates nonproperty", 67 | "data": {"fxo": [1, 2]}, 68 | "valid": true 69 | }, 70 | { 71 | "description": "patternProperty invalidates nonproperty", 72 | "data": {"fxo": []}, 73 | "valid": false 74 | }, 75 | { 76 | "description": "additionalProperty ignores property", 77 | "data": {"bar": []}, 78 | "valid": true 79 | }, 80 | { 81 | "description": "additionalProperty validates others", 82 | "data": {"quux": 3}, 83 | "valid": true 84 | }, 85 | { 86 | "description": "additionalProperty invalidates others", 87 | "data": {"quux": "foo"}, 88 | "valid": false 89 | } 90 | ] 91 | } 92 | ] 93 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/refRemote.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "remote ref", 4 | "schema": {"$ref": "http://localhost:1234/integer.json"}, 5 | "tests": [ 6 | { 7 | "description": "remote ref valid", 8 | "data": 1, 9 | "valid": true 10 | }, 11 | { 12 | "description": "remote ref invalid", 13 | "data": "a", 14 | "valid": false 15 | } 16 | ] 17 | }, 18 | { 19 | "description": "fragment within remote ref", 20 | "schema": {"$ref": "http://localhost:1234/subSchemas.json#/integer"}, 21 | "tests": [ 22 | { 23 | "description": "remote fragment valid", 24 | "data": 1, 25 | "valid": true 26 | }, 27 | { 28 | "description": "remote fragment invalid", 29 | "data": "a", 30 | "valid": false 31 | } 32 | ] 33 | }, 34 | { 35 | "description": "ref within remote ref", 36 | "schema": { 37 | "$ref": "http://localhost:1234/subSchemas.json#/refToInteger" 38 | }, 39 | "tests": [ 40 | { 41 | "description": "ref within ref valid", 42 | "data": 1, 43 | "valid": true 44 | }, 45 | { 46 | "description": "ref within ref invalid", 47 | "data": "a", 48 | "valid": false 49 | } 50 | ] 51 | }, 52 | { 53 | "description": "change resolution scope", 54 | "schema": { 55 | "id": "http://localhost:1234/", 56 | "items": { 57 | "id": "folder/", 58 | "items": {"$ref": "folderInteger.json"} 59 | } 60 | }, 61 | "tests": [ 62 | { 63 | "description": "changed scope ref valid", 64 | "data": [[1]], 65 | "valid": true 66 | }, 67 | { 68 | "description": "changed scope ref invalid", 69 | "data": [["a"]], 70 | "valid": false 71 | } 72 | ] 73 | } 74 | ] 75 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/required.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "required validation", 4 | "schema": { 5 | "properties": { 6 | "foo": {}, 7 | "bar": {} 8 | }, 9 | "required": ["foo"] 10 | }, 11 | "tests": [ 12 | { 13 | "description": "present required property is valid", 14 | "data": {"foo": 1}, 15 | "valid": true 16 | }, 17 | { 18 | "description": "non-present required property is invalid", 19 | "data": {"bar": 1}, 20 | "valid": false 21 | } 22 | ] 23 | }, 24 | { 25 | "description": "required default validation", 26 | "schema": { 27 | "properties": { 28 | "foo": {} 29 | } 30 | }, 31 | "tests": [ 32 | { 33 | "description": "not required by default", 34 | "data": {}, 35 | "valid": true 36 | } 37 | ] 38 | } 39 | ] 40 | -------------------------------------------------------------------------------- /bin/jsonschema/tests/draft4/uniqueItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "uniqueItems validation", 4 | "schema": {"uniqueItems": true}, 5 | "tests": [ 6 | { 7 | "description": "unique array of integers is valid", 8 | "data": [1, 2], 9 | "valid": true 10 | }, 11 | { 12 | "description": "non-unique array of integers is invalid", 13 | "data": [1, 1], 14 | "valid": false 15 | }, 16 | { 17 | "description": "numbers are unique if mathematically unequal", 18 | "data": [1.0, 1.00, 1], 19 | "valid": false 20 | }, 21 | { 22 | "description": "unique array of objects is valid", 23 | "data": [{"foo": "bar"}, {"foo": "baz"}], 24 | "valid": true 25 | }, 26 | { 27 | "description": "non-unique array of objects is invalid", 28 | "data": [{"foo": "bar"}, {"foo": "bar"}], 29 | "valid": false 30 | }, 31 | { 32 | "description": "unique array of nested objects is valid", 33 | "data": [ 34 | {"foo": {"bar" : {"baz" : true}}}, 35 | {"foo": {"bar" : {"baz" : false}}} 36 | ], 37 | "valid": true 38 | }, 39 | { 40 | "description": "non-unique array of nested objects is invalid", 41 | "data": [ 42 | {"foo": {"bar" : {"baz" : true}}}, 43 | {"foo": {"bar" : {"baz" : true}}} 44 | ], 45 | "valid": false 46 | }, 47 | { 48 | "description": "unique array of arrays is valid", 49 | "data": [["foo"], ["bar"]], 50 | "valid": true 51 | }, 52 | { 53 | "description": "non-unique array of arrays is invalid", 54 | "data": [["foo"], ["foo"]], 55 | "valid": false 56 | }, 57 | { 58 | "description": "1 and true are unique", 59 | "data": [1, true], 60 | "valid": true 61 | }, 62 | { 63 | "description": "0 and false are unique", 64 | "data": [0, false], 65 | "valid": true 66 | }, 67 | { 68 | "description": "unique heterogeneous types are valid", 69 | "data": [{}, [1], true, null, 1], 70 | "valid": true 71 | }, 72 | { 73 | "description": "non-unique heterogeneous types are invalid", 74 | "data": [{}, [1], true, null, {}, 1], 75 | "valid": false 76 | } 77 | ] 78 | } 79 | ] 80 | -------------------------------------------------------------------------------- /bin/jsonschema/tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 1.6 3 | envlist = py27 4 | skipsdist = True 5 | 6 | [testenv] 7 | deps = jsonschema 8 | commands = {envpython} bin/jsonschema_suite check 9 | -------------------------------------------------------------------------------- /bin/types/booleans.json: -------------------------------------------------------------------------------- 1 | [ 2 | true, 3 | true, 4 | false, 5 | false, 6 | true, 7 | true, 8 | true, 9 | false, 10 | false, 11 | true, 12 | false, 13 | false, 14 | true, 15 | false, 16 | false, 17 | false, 18 | true, 19 | false, 20 | false, 21 | true, 22 | true, 23 | false, 24 | true, 25 | true, 26 | true, 27 | false, 28 | false, 29 | false, 30 | true, 31 | false, 32 | true, 33 | false, 34 | false, 35 | true, 36 | true, 37 | true, 38 | true, 39 | true, 40 | true, 41 | false, 42 | false, 43 | true, 44 | false, 45 | false, 46 | false, 47 | true, 48 | true, 49 | false, 50 | true, 51 | true, 52 | false, 53 | true, 54 | false, 55 | true, 56 | true, 57 | true, 58 | false, 59 | false, 60 | false, 61 | true, 62 | false, 63 | false, 64 | false, 65 | true, 66 | true, 67 | false, 68 | true, 69 | true, 70 | true, 71 | true, 72 | true, 73 | true, 74 | true, 75 | true, 76 | false, 77 | false, 78 | false, 79 | false, 80 | false, 81 | true, 82 | true, 83 | true, 84 | true, 85 | true, 86 | true, 87 | true, 88 | false, 89 | false, 90 | false, 91 | true, 92 | false, 93 | false, 94 | false, 95 | true, 96 | true, 97 | true, 98 | false, 99 | false, 100 | true, 101 | false 102 | ] -------------------------------------------------------------------------------- /bin/types/floats.json: -------------------------------------------------------------------------------- 1 | [ 2 | 135.747111636, 3 | 123.377054008, 4 | 140.527504552, 5 | -72.299143906, 6 | -23.851678949, 7 | 73.586193519, 8 | -158.299382442, 9 | 177.477876032, 10 | 32.268518982, 11 | -139.560009969, 12 | 115.203105183, 13 | -106.025823607, 14 | 167.224138231, 15 | 103.378383732, 16 | -97.498486285, 17 | 18.184723416, 18 | 69.137075711, 19 | 33.849002681, 20 | -120.185228215, 21 | -20.841408615, 22 | -172.659492727, 23 | -2.691464061, 24 | 22.426164066, 25 | -98.416909437, 26 | -31.603082708, 27 | -85.072296561, 28 | 108.620987395, 29 | -43.127078238, 30 | -126.473562057, 31 | -158.595489097, 32 | -57.890678254, 33 | -13.254016573, 34 | -85.024504709, 35 | 171.663552644, 36 | -146.495558248, 37 | -10.606748276, 38 | -118.786969354, 39 | 153.352057804, 40 | -45.215545083, 41 | 37.038725288, 42 | 106.344071897, 43 | -64.607402031, 44 | 85.148030911, 45 | 28.897784566, 46 | 39.51082061, 47 | 20.450382102, 48 | -113.174943618, 49 | 71.60785784, 50 | -168.202648062, 51 | -157.338200017, 52 | 10.879588527, 53 | -114.261694831, 54 | -5.622927072, 55 | -173.330830616, 56 | -29.47002003, 57 | -39.829034201, 58 | 50.031545162, 59 | 82.815735508, 60 | -119.188760828, 61 | -48.455928081, 62 | 163.964263034, 63 | 46.30378861, 64 | -26.248889762, 65 | -47.354615322, 66 | 155.388677633, 67 | -166.710356904, 68 | 42.987233558, 69 | 144.275297374, 70 | 37.394383186, 71 | -122.550388725, 72 | 177.469945914, 73 | 101.104677413, 74 | 109.429869885, 75 | -104.919625624, 76 | 147.522756541, 77 | -81.294703727, 78 | 122.744731363, 79 | 81.803603684, 80 | 26.321556167, 81 | 147.045441354, 82 | 147.256895816, 83 | -174.211095908, 84 | 52.518769316, 85 | -78.58250334, 86 | -173.356685435, 87 | -107.728209264, 88 | -69.982325771, 89 | -113.776095893, 90 | -35.785267074, 91 | -105.748545976, 92 | -30.206523864, 93 | -76.185311723, 94 | -126.400112781, 95 | -26.864958639, 96 | 56.840053629, 97 | 93.781553535, 98 | -116.002949803, 99 | -46.617140948, 100 | 176.846840093, 101 | -144.24821335 102 | ] 103 | -------------------------------------------------------------------------------- /bin/types/integers.json: -------------------------------------------------------------------------------- 1 | [ 2 | 8125686, 3 | 8958709, 4 | 5976222, 5 | 1889524, 6 | 7968493, 7 | 1357486, 8 | 118415, 9 | 7081097, 10 | 4635968, 11 | 7555332, 12 | 2270233, 13 | 3428352, 14 | 8699968, 15 | 2087333, 16 | 7861337, 17 | 7554440, 18 | 2017031, 19 | 7981692, 20 | 6060687, 21 | 1877715, 22 | 3297474, 23 | 8373177, 24 | 6158629, 25 | 7853641, 26 | 3004441, 27 | 9650406, 28 | 2695251, 29 | 1180761, 30 | 4988426, 31 | 6043805, 32 | 8063373, 33 | 6103218, 34 | 2848339, 35 | 8188690, 36 | 9235573, 37 | 5949816, 38 | 6116081, 39 | 6471138, 40 | 3354531, 41 | 4787414, 42 | 9660600, 43 | 942529, 44 | 7278535, 45 | 7967399, 46 | 554292, 47 | 1436493, 48 | 267319, 49 | 2606657, 50 | 7900601, 51 | 4276634, 52 | 7996757, 53 | 8544466, 54 | 7266469, 55 | 3301373, 56 | 4005350, 57 | 6437652, 58 | 7717672, 59 | 7126292, 60 | 8588394, 61 | 2127902, 62 | 7410190, 63 | 1517806, 64 | 4583602, 65 | 3123440, 66 | 7747613, 67 | 5029464, 68 | 9834390, 69 | 3087227, 70 | 4913822, 71 | 7550487, 72 | 4518144, 73 | 5862588, 74 | 1778599, 75 | 9493290, 76 | 5588455, 77 | 3638706, 78 | 7394293, 79 | 4294719, 80 | 3837830, 81 | 6381878, 82 | 7175866, 83 | 8575492, 84 | 1415229, 85 | 1453733, 86 | 6972404, 87 | 9782571, 88 | 4234063, 89 | 7117418, 90 | 7293130, 91 | 8057071, 92 | 9345285, 93 | 7626648, 94 | 3358911, 95 | 4574537, 96 | 9371826, 97 | 7627107, 98 | 6154093, 99 | 5392367, 100 | 5398105, 101 | 6956377 102 | ] -------------------------------------------------------------------------------- /bin/types/nulls.json: -------------------------------------------------------------------------------- 1 | [ 2 | null, 3 | null, 4 | null, 5 | null, 6 | null, 7 | null, 8 | null, 9 | null, 10 | null, 11 | null, 12 | null, 13 | null, 14 | null, 15 | null, 16 | null, 17 | null, 18 | null, 19 | null, 20 | null, 21 | null, 22 | null, 23 | null, 24 | null, 25 | null, 26 | null, 27 | null, 28 | null, 29 | null, 30 | null, 31 | null, 32 | null, 33 | null, 34 | null, 35 | null, 36 | null, 37 | null, 38 | null, 39 | null, 40 | null, 41 | null, 42 | null, 43 | null, 44 | null, 45 | null, 46 | null, 47 | null, 48 | null, 49 | null, 50 | null, 51 | null, 52 | null, 53 | null, 54 | null, 55 | null, 56 | null, 57 | null, 58 | null, 59 | null, 60 | null, 61 | null, 62 | null, 63 | null, 64 | null, 65 | null, 66 | null, 67 | null, 68 | null, 69 | null, 70 | null, 71 | null, 72 | null, 73 | null, 74 | null, 75 | null, 76 | null, 77 | null, 78 | null, 79 | null, 80 | null, 81 | null, 82 | null, 83 | null, 84 | null, 85 | null, 86 | null, 87 | null, 88 | null, 89 | null, 90 | null, 91 | null, 92 | null, 93 | null, 94 | null, 95 | null, 96 | null, 97 | null, 98 | null, 99 | null, 100 | null, 101 | null 102 | ] -------------------------------------------------------------------------------- /bin/types/readme.txt: -------------------------------------------------------------------------------- 1 | Test data obtained from https://github.com/xpol/lua-rapidjson/tree/master/performance 2 | -------------------------------------------------------------------------------- /bin/unittestschema/allOf_address.json: -------------------------------------------------------------------------------- 1 | { 2 | "allOf": [ 3 | { 4 | "$ref": "http://localhost:1234/address.json#" 5 | } 6 | ] 7 | } -------------------------------------------------------------------------------- /bin/unittestschema/anyOf_address.json: -------------------------------------------------------------------------------- 1 | { 2 | "anyOf": [ 3 | { 4 | "$ref": "http://localhost:1234/address.json#" 5 | } 6 | ] 7 | } -------------------------------------------------------------------------------- /bin/unittestschema/idandref.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "http://example.com/root.json", 3 | "definitions": { 4 | "A": { 5 | "id": "#foo", 6 | "type": "integer" 7 | }, 8 | "B": { 9 | "id": "other.json", 10 | "definitions": { 11 | "X": { 12 | "id": "#bar", 13 | "type": "boolean" 14 | }, 15 | "Y": { 16 | "$ref": "#/definitions/X" 17 | }, 18 | "W": { 19 | "$ref": "#/definitions/Y" 20 | }, 21 | "Z": { 22 | "$ref": "#bar" 23 | }, 24 | "N": { 25 | "properties": { 26 | "NX": { 27 | "$ref": "#/definitions/X" 28 | } 29 | } 30 | } 31 | } 32 | } 33 | }, 34 | "properties": { 35 | "PA1": { 36 | "$ref": "http://example.com/root.json#/definitions/A" 37 | }, 38 | "PA2": { 39 | "$ref": "#/definitions/A" 40 | }, 41 | "PA3": { 42 | "$ref": "#foo" 43 | }, 44 | "PX1": { 45 | "$ref": "#/definitions/B/definitions/X" 46 | }, 47 | "PX2Y": { 48 | "$ref": "#/definitions/B/definitions/Y" 49 | }, 50 | "PX3Z": { 51 | "$ref": "#/definitions/B/definitions/Z" 52 | }, 53 | "PX4": { 54 | "$ref": "http://example.com/other.json#/definitions/X" 55 | }, 56 | "PX5": { 57 | "$ref": "other.json#/definitions/X" 58 | }, 59 | "PX6": { 60 | "$ref": "other.json#bar" 61 | }, 62 | "PX7W": { 63 | "$ref": "#/definitions/B/definitions/W" 64 | }, 65 | "PX8N": { 66 | "$ref": "#/definitions/B/definitions/N" 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /bin/unittestschema/oneOf_address.json: -------------------------------------------------------------------------------- 1 | { 2 | "oneOf": [ 3 | { 4 | "$ref": "http://localhost:1234/address.json#" 5 | } 6 | ] 7 | } -------------------------------------------------------------------------------- /contrib/natvis/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Bart Muzzin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | Derived from: 24 | 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 mojmir svoboda 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in all 37 | copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 45 | SOFTWARE. 46 | -------------------------------------------------------------------------------- /contrib/natvis/README.md: -------------------------------------------------------------------------------- 1 | # rapidjson.natvis 2 | 3 | This file can be used as a [Visual Studio Visualizer](https://docs.microsoft.com/en-gb/visualstudio/debugger/create-custom-views-of-native-objects) to aid in visualizing rapidjson structures within the Visual Studio debugger. Natvis visualizers are supported in Visual Studio 2012 and later. To install, copy the file into this directory: 4 | 5 | `%USERPROFILE%\Documents\Visual Studio 2012\Visualizers` 6 | 7 | Each version of Visual Studio has a similar directory, it must be copied into each directory to be used with that particular version. In Visual Studio 2015 and later, this can be done without restarting Visual Studio (a new debugging session must be started). 8 | -------------------------------------------------------------------------------- /contrib/natvis/rapidjson.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | null 6 | true 7 | false 8 | {(const Ch*)data_.ss.str,na} 9 | {(const Ch*)((size_t)data_.s.str & 0x0000FFFFFFFFFFFF),[data_.s.length]na} 10 | {data_.n.i.i} 11 | {data_.n.u.u} 12 | {data_.n.i64} 13 | {data_.n.u64} 14 | {data_.n.d} 15 | Object members={data_.o.size} 16 | Array members={data_.a.size} 17 | 18 | data_.o.size 19 | data_.o.capacity 20 | 21 | data_.o.size 22 | 23 | (rapidjson::GenericMember<$T1,$T2>*)(((size_t)data_.o.members) & 0x0000FFFFFFFFFFFF) 24 | 25 | 26 | data_.a.size 27 | data_.a.capacity 28 | 29 | data_.a.size 30 | 31 | (rapidjson::GenericValue<$T1,$T2>*)(((size_t)data_.a.elements) & 0x0000FFFFFFFFFFFF) 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Doxygen) 2 | 3 | IF(NOT DOXYGEN_FOUND) 4 | MESSAGE(STATUS "No Doxygen found. Documentation won't be built") 5 | ELSE() 6 | file(GLOB SOURCES ${CMAKE_CURRENT_LIST_DIR}/../include/*) 7 | file(GLOB MARKDOWN_DOC ${CMAKE_CURRENT_LIST_DIR}/../doc/*.md) 8 | list(APPEND MARKDOWN_DOC ${CMAKE_CURRENT_LIST_DIR}/../readme.md) 9 | 10 | CONFIGURE_FILE(Doxyfile.in Doxyfile @ONLY) 11 | CONFIGURE_FILE(Doxyfile.zh-cn.in Doxyfile.zh-cn @ONLY) 12 | 13 | file(GLOB DOXYFILES ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile*) 14 | 15 | add_custom_command(OUTPUT html 16 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 17 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.zh-cn 18 | COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/html 19 | DEPENDS ${MARKDOWN_DOC} ${SOURCES} ${DOXYFILES} 20 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../ 21 | ) 22 | 23 | add_custom_target(doc ALL DEPENDS html) 24 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html 25 | DESTINATION ${DOC_INSTALL_DIR} 26 | COMPONENT doc) 27 | ENDIF() 28 | -------------------------------------------------------------------------------- /doc/diagram/architecture.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | nodesep=0.5 8 | penwidth=0.5 9 | colorscheme=spectral7 10 | 11 | node [shape=box, fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5, style=filled, fillcolor=white] 12 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 13 | 14 | subgraph cluster1 { 15 | margin="10,10" 16 | labeljust="left" 17 | label = "SAX" 18 | style=filled 19 | fillcolor=6 20 | 21 | Reader -> Writer [style=invis] 22 | } 23 | 24 | subgraph cluster2 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "DOM" 28 | style=filled 29 | fillcolor=7 30 | 31 | Value 32 | Document 33 | } 34 | 35 | Handler [label="<>\nHandler"] 36 | 37 | { 38 | edge [arrowtail=onormal, dir=back] 39 | Value -> Document 40 | Handler -> Document 41 | Handler -> Writer 42 | } 43 | 44 | { 45 | edge [arrowhead=vee, style=dashed, constraint=false] 46 | Reader -> Handler [label="calls"] 47 | Value -> Handler [label="calls"] 48 | Document -> Reader [label="uses"] 49 | } 50 | } -------------------------------------------------------------------------------- /doc/diagram/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/architecture.png -------------------------------------------------------------------------------- /doc/diagram/insituparsing.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | oldjson [label="\{|\"|m|s|g|\"|:|\"|H|e|l|l|o|\\|n|W|o|r|l|d|!|\"|,|\"|\\|u|0|0|7|3|t|a|r|s|\"|:|1|0|\}", xlabel="Before Parsing"] 15 | //newjson [label="\{|\"|m|s|g|\\0|:|\"|H|e|l|l|o|\\n|W|o|r|l|d|!|\\0|\"|,|\"|s|t|a|r|s|\\0|t|a|r|s|:|1|0|\}", xlabel="After Parsing"] 16 | newjson [shape=plaintext, label=< 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
{"msg\\0:"Hello\\nWorld!\\0","stars\\0tars:10}
28 | >, xlabel="After Parsing"] 29 | } 30 | 31 | subgraph cluster1 { 32 | margin="10,10" 33 | labeljust="left" 34 | label = "Document by In situ Parsing" 35 | style=filled 36 | fillcolor=gray95 37 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 38 | 39 | root [label="{object|}", fillcolor=3] 40 | 41 | { 42 | msg [label="{string|
}", fillcolor=5] 43 | helloworld [label="{string|}", fillcolor=5] 44 | stars [label="{string|}", fillcolor=5] 45 | ten [label="{number|10}", fillcolor=6] 46 | } 47 | } 48 | 49 | oldjson -> root [label=" ParseInsitu()" lhead="cluster1"] 50 | edge [arrowhead=vee] 51 | root -> { msg; stars } 52 | 53 | edge [arrowhead="none"] 54 | msg -> helloworld 55 | stars -> ten 56 | 57 | { 58 | edge [arrowhead=vee, arrowtail=dot, arrowsize=0.5, dir=both, tailclip=false] 59 | msg:a:c -> newjson:a 60 | helloworld:a:c -> newjson:b 61 | stars:a:c -> newjson:c 62 | } 63 | 64 | //oldjson -> newjson [style=invis] 65 | } -------------------------------------------------------------------------------- /doc/diagram/insituparsing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/insituparsing.png -------------------------------------------------------------------------------- /doc/diagram/iterative-parser-states-diagram.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | fontname="Inconsolata, Consolas" 3 | fontsize=10 4 | margin="0,0" 5 | penwidth=0.0 6 | 7 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 8 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 9 | 10 | node [shape = doublecircle]; Start; Finish; 11 | node [shape = box; style = "rounded, filled"; fillcolor=white ]; 12 | 13 | Start -> ArrayInitial [label=" ["]; 14 | Start -> ObjectInitial [label=" {"]; 15 | 16 | subgraph clusterArray { 17 | margin="10,10" 18 | style=filled 19 | fillcolor=gray95 20 | label = "Array" 21 | 22 | ArrayInitial; Element; ElementDelimiter; ArrayFinish; 23 | } 24 | 25 | subgraph clusterObject { 26 | margin="10,10" 27 | style=filled 28 | fillcolor=gray95 29 | label = "Object" 30 | 31 | ObjectInitial; MemberKey; KeyValueDelimiter; MemberValue; MemberDelimiter; ObjectFinish; 32 | } 33 | 34 | ArrayInitial -> ArrayInitial [label="["]; 35 | ArrayInitial -> ArrayFinish [label=" ]"]; 36 | ArrayInitial -> ObjectInitial [label="{", constraint=false]; 37 | ArrayInitial -> Element [label="string\nfalse\ntrue\nnull\nnumber"]; 38 | 39 | Element -> ArrayFinish [label="]"]; 40 | Element -> ElementDelimiter [label=","]; 41 | 42 | ElementDelimiter -> ArrayInitial [label=" ["]; 43 | ElementDelimiter -> ObjectInitial [label="{"]; 44 | ElementDelimiter -> Element [label="string\nfalse\ntrue\nnull\nnumber"]; 45 | 46 | ObjectInitial -> ObjectFinish [label=" }"]; 47 | ObjectInitial -> MemberKey [label=" string "]; 48 | 49 | MemberKey -> KeyValueDelimiter [label=":"]; 50 | 51 | KeyValueDelimiter -> ArrayInitial [label="["]; 52 | KeyValueDelimiter -> ObjectInitial [label=" {"]; 53 | KeyValueDelimiter -> MemberValue [label=" string\n false\n true\n null\n number"]; 54 | 55 | MemberValue -> ObjectFinish [label="}"]; 56 | MemberValue -> MemberDelimiter [label=","]; 57 | 58 | MemberDelimiter -> MemberKey [label=" string "]; 59 | 60 | ArrayFinish -> Finish; 61 | ObjectFinish -> Finish; 62 | } 63 | -------------------------------------------------------------------------------- /doc/diagram/iterative-parser-states-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/iterative-parser-states-diagram.png -------------------------------------------------------------------------------- /doc/diagram/makefile: -------------------------------------------------------------------------------- 1 | %.pdf: %.dot 2 | dot $< -Tpdf -o $@ 3 | 4 | %.png: %.dot 5 | dot $< -Tpng -o $@ 6 | 7 | DOTFILES = $(basename $(wildcard *.dot)) 8 | all: $(addsuffix .png, $(DOTFILES)) $(addsuffix .pdf, $(DOTFILES)) 9 | -------------------------------------------------------------------------------- /doc/diagram/move1.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Before" 16 | style=filled 17 | fillcolor=gray95 18 | 19 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 20 | 21 | { 22 | rank = same 23 | b1 [label="{b:number|456}", fillcolor=6] 24 | a1 [label="{a:number|123}", fillcolor=6] 25 | } 26 | 27 | a1 -> b1 [style="dashed", label="Move", dir=back] 28 | } 29 | 30 | subgraph cluster2 { 31 | margin="10,10" 32 | labeljust="left" 33 | label = "After" 34 | style=filled 35 | fillcolor=gray95 36 | 37 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 38 | 39 | { 40 | rank = same 41 | b2 [label="{b:null|}", fillcolor=1] 42 | a2 [label="{a:number|456}", fillcolor=6] 43 | } 44 | a2 -> b2 [style=invis, dir=back] 45 | } 46 | b1 -> b2 [style=invis] 47 | } -------------------------------------------------------------------------------- /doc/diagram/move1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/move1.png -------------------------------------------------------------------------------- /doc/diagram/move2.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Before Copying (Hypothetic)" 16 | style=filled 17 | fillcolor=gray95 18 | 19 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 20 | 21 | c1 [label="{contacts:array|}", fillcolor=4] 22 | c11 [label="{|}"] 23 | c12 [label="{|}"] 24 | c13 [shape="none", label="...", style="solid"] 25 | o1 [label="{o:object|}", fillcolor=3] 26 | ghost [label="{o:object|}", style=invis] 27 | 28 | c1 -> o1 [style="dashed", label="AddMember", constraint=false] 29 | 30 | edge [arrowhead=vee] 31 | c1 -> { c11; c12; c13 } 32 | o1 -> ghost [style=invis] 33 | } 34 | 35 | subgraph cluster2 { 36 | margin="10,10" 37 | labeljust="left" 38 | label = "After Copying (Hypothetic)" 39 | style=filled 40 | fillcolor=gray95 41 | 42 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 43 | 44 | c2 [label="{contacts:array|}", fillcolor=4] 45 | c3 [label="{array|}", fillcolor=4] 46 | c21 [label="{|}"] 47 | c22 [label="{|}"] 48 | c23 [shape=none, label="...", style="solid"] 49 | o2 [label="{o:object|}", fillcolor=3] 50 | cs [label="{string|\"contacts\"}", fillcolor=5] 51 | c31 [label="{|}"] 52 | c32 [label="{|}"] 53 | c33 [shape="none", label="...", style="solid"] 54 | 55 | edge [arrowhead=vee] 56 | c2 -> { c21; c22; c23 } 57 | o2 -> cs 58 | cs -> c3 [arrowhead=none] 59 | c3 -> { c31; c32; c33 } 60 | } 61 | ghost -> o2 [style=invis] 62 | } 63 | -------------------------------------------------------------------------------- /doc/diagram/move2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/move2.png -------------------------------------------------------------------------------- /doc/diagram/move3.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | forcelabels=true 9 | 10 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 11 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 12 | 13 | subgraph cluster1 { 14 | margin="10,10" 15 | labeljust="left" 16 | label = "Before Moving" 17 | style=filled 18 | fillcolor=gray95 19 | 20 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 21 | 22 | c1 [label="{contacts:array|}", fillcolor=4] 23 | c11 [label="{|}"] 24 | c12 [label="{|}"] 25 | c13 [shape=none, label="...", style="solid"] 26 | o1 [label="{o:object|}", fillcolor=3] 27 | ghost [label="{o:object|}", style=invis] 28 | 29 | c1 -> o1 [style="dashed", constraint=false, label="AddMember"] 30 | 31 | edge [arrowhead=vee] 32 | c1 -> { c11; c12; c13 } 33 | o1 -> ghost [style=invis] 34 | } 35 | 36 | subgraph cluster2 { 37 | margin="10,10" 38 | labeljust="left" 39 | label = "After Moving" 40 | style=filled 41 | fillcolor=gray95 42 | 43 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 44 | 45 | c2 [label="{contacts:null|}", fillcolor=1] 46 | c3 [label="{array|}", fillcolor=4] 47 | c21 [label="{|}"] 48 | c22 [label="{|}"] 49 | c23 [shape="none", label="...", style="solid"] 50 | o2 [label="{o:object|}", fillcolor=3] 51 | cs [label="{string|\"contacts\"}", fillcolor=5] 52 | c2 -> o2 [style="dashed", constraint=false, label="AddMember", style=invis] 53 | 54 | edge [arrowhead=vee] 55 | c3 -> { c21; c22; c23 } 56 | o2 -> cs 57 | cs -> c3 [arrowhead=none] 58 | } 59 | ghost -> o2 [style=invis] 60 | } 61 | -------------------------------------------------------------------------------- /doc/diagram/move3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/move3.png -------------------------------------------------------------------------------- /doc/diagram/normalparsing.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | normaljson [label="\{|\"|m|s|g|\"|:|\"|H|e|l|l|o|\\|n|W|o|r|l|d|!|\"|,|\"|\\|u|0|0|7|3|t|a|r|s\"|:|1|0|\}"] 15 | 16 | { 17 | rank = same 18 | msgstring [label="m|s|g|\\0"] 19 | helloworldstring [label="H|e|l|l|o|\\n|W|o|r|l|d|!|\\0"] 20 | starsstring [label="s|t|a|r|s\\0"] 21 | } 22 | } 23 | 24 | subgraph cluster1 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "Document by Normal Parsing" 28 | style=filled 29 | fillcolor=gray95 30 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 31 | 32 | root [label="{object|}", fillcolor=3] 33 | 34 | { 35 | msg [label="{string|}", fillcolor=5] 36 | helloworld [label="{string|}", fillcolor=5] 37 | stars [label="{string|}", fillcolor=5] 38 | ten [label="{number|10}", fillcolor=6] 39 | } 40 | } 41 | 42 | normaljson -> root [label=" Parse()" lhead="cluster1"] 43 | edge [arrowhead=vee] 44 | root -> { msg; stars } 45 | 46 | edge [arrowhead="none"] 47 | msg -> helloworld 48 | stars -> ten 49 | 50 | edge [arrowhead=vee, arrowtail=dot, arrowsize=0.5, dir=both, tailclip=false] 51 | msg:a:c -> msgstring:w 52 | helloworld:a:c -> helloworldstring:w 53 | stars:a:c -> starsstring:w 54 | 55 | msgstring -> helloworldstring -> starsstring [style=invis] 56 | } -------------------------------------------------------------------------------- /doc/diagram/normalparsing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/normalparsing.png -------------------------------------------------------------------------------- /doc/diagram/simpledom.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | srcjson [label="\{|\"|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|0|\}"] 15 | dstjson [label="\{|\"|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|1|\}"] 16 | } 17 | 18 | { 19 | node [shape="box", style="filled", fillcolor="gray95"] 20 | Document2 [label="(Modified) Document"] 21 | Writer 22 | } 23 | 24 | subgraph cluster1 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "Document" 28 | style=filled 29 | fillcolor=gray95 30 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 31 | 32 | root [label="{object|}", fillcolor=3] 33 | 34 | { 35 | project [label="{string|\"project\"}", fillcolor=5] 36 | rapidjson [label="{string|\"rapidjson\"}", fillcolor=5] 37 | stars [label="{string|\"stars\"}", fillcolor=5] 38 | ten [label="{number|10}", fillcolor=6] 39 | } 40 | 41 | edge [arrowhead=vee] 42 | root -> { project; stars } 43 | 44 | edge [arrowhead="none"] 45 | project -> rapidjson 46 | stars -> ten 47 | } 48 | 49 | srcjson -> root [label=" Parse()", lhead="cluster1"] 50 | 51 | ten -> Document2 [label=" Increase \"stars\"", ltail="cluster1" ] 52 | Document2 -> Writer [label=" Traverse DOM by Accept()"] 53 | Writer -> dstjson [label=" Output to StringBuffer"] 54 | } -------------------------------------------------------------------------------- /doc/diagram/simpledom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/simpledom.png -------------------------------------------------------------------------------- /doc/diagram/tutorial.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Document" 16 | style=filled 17 | fillcolor=gray95 18 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 19 | 20 | root [label="{object|}", fillcolor=3] 21 | 22 | { 23 | hello [label="{string|\"hello\"}", fillcolor=5] 24 | t [label="{string|\"t\"}", fillcolor=5] 25 | f [label="{string|\"f\"}", fillcolor=5] 26 | n [label="{string|\"n\"}", fillcolor=5] 27 | i [label="{string|\"i\"}", fillcolor=5] 28 | pi [label="{string|\"pi\"}", fillcolor=5] 29 | a [label="{string|\"a\"}", fillcolor=5] 30 | 31 | world [label="{string|\"world\"}", fillcolor=5] 32 | true [label="{true|}", fillcolor=7] 33 | false [label="{false|}", fillcolor=2] 34 | null [label="{null|}", fillcolor=1] 35 | i1 [label="{number|123}", fillcolor=6] 36 | pi1 [label="{number|3.1416}", fillcolor=6] 37 | array [label="{array|size=4}", fillcolor=4] 38 | 39 | a1 [label="{number|1}", fillcolor=6] 40 | a2 [label="{number|2}", fillcolor=6] 41 | a3 [label="{number|3}", fillcolor=6] 42 | a4 [label="{number|4}", fillcolor=6] 43 | } 44 | 45 | edge [arrowhead=vee] 46 | root -> { hello; t; f; n; i; pi; a } 47 | array -> { a1; a2; a3; a4 } 48 | 49 | edge [arrowhead=none] 50 | hello -> world 51 | t -> true 52 | f -> false 53 | n -> null 54 | i -> i1 55 | pi -> pi1 56 | a -> array 57 | } 58 | } -------------------------------------------------------------------------------- /doc/diagram/tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/tutorial.png -------------------------------------------------------------------------------- /doc/diagram/utilityclass.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR 3 | compound=true 4 | fontname="Inconsolata, Consolas" 5 | fontsize=10 6 | margin="0,0" 7 | ranksep=0.3 8 | nodesep=0.15 9 | penwidth=0.5 10 | colorscheme=spectral7 11 | 12 | node [shape=box, fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5, style=filled, fillcolor=white] 13 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 14 | 15 | subgraph cluster0 { 16 | style=filled 17 | fillcolor=4 18 | 19 | Encoding [label="<>\nEncoding"] 20 | 21 | edge [arrowtail=onormal, dir=back] 22 | Encoding -> { UTF8; UTF16; UTF32; ASCII; AutoUTF } 23 | UTF16 -> { UTF16LE; UTF16BE } 24 | UTF32 -> { UTF32LE; UTF32BE } 25 | } 26 | 27 | subgraph cluster1 { 28 | style=filled 29 | fillcolor=5 30 | 31 | Stream [label="<>\nStream"] 32 | InputByteStream [label="<>\nInputByteStream"] 33 | OutputByteStream [label="<>\nOutputByteStream"] 34 | 35 | edge [arrowtail=onormal, dir=back] 36 | Stream -> { 37 | StringStream; InsituStringStream; StringBuffer; 38 | EncodedInputStream; EncodedOutputStream; 39 | AutoUTFInputStream; AutoUTFOutputStream 40 | InputByteStream; OutputByteStream 41 | } 42 | 43 | InputByteStream -> { MemoryStream; FlieReadStream } 44 | OutputByteStream -> { MemoryBuffer; FileWriteStream } 45 | } 46 | 47 | subgraph cluster2 { 48 | style=filled 49 | fillcolor=3 50 | 51 | Allocator [label="<>\nAllocator"] 52 | 53 | edge [arrowtail=onormal, dir=back] 54 | Allocator -> { CrtAllocator; MemoryPoolAllocator } 55 | } 56 | 57 | { 58 | edge [arrowtail=odiamond, arrowhead=vee, dir=both] 59 | EncodedInputStream -> InputByteStream 60 | EncodedOutputStream -> OutputByteStream 61 | AutoUTFInputStream -> InputByteStream 62 | AutoUTFOutputStream -> OutputByteStream 63 | MemoryPoolAllocator -> Allocator [label="base", tailport=s] 64 | } 65 | 66 | { 67 | edge [arrowhead=vee, style=dashed] 68 | AutoUTFInputStream -> AutoUTF 69 | AutoUTFOutputStream -> AutoUTF 70 | } 71 | 72 | //UTF32LE -> Stream [style=invis] 73 | } -------------------------------------------------------------------------------- /doc/diagram/utilityclass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/diagram/utilityclass.png -------------------------------------------------------------------------------- /doc/features.zh-cn.md: -------------------------------------------------------------------------------- 1 | # 特点 2 | 3 | ## 总体 4 | 5 | * 跨平台 6 | * 编译器:Visual Studio、gcc、clang 等 7 | * 架构:x86、x64、ARM 等 8 | * 操作系统:Windows、Mac OS X、Linux、iOS、Android 等 9 | * 容易安装 10 | * 只有头文件的库。只需把头文件复制至你的项目中。 11 | * 独立、最小依赖 12 | * 不需依赖 STL、BOOST 等。 13 | * 只包含 ``, ``, ``, ``, ``, ``。 14 | * 没使用 C++ 异常、RTTI 15 | * 高性能 16 | * 使用模版及内联函数去降低函数调用开销。 17 | * 内部经优化的 Grisu2 及浮点数解析实现。 18 | * 可选的 SSE2/SSE4.2 支持。 19 | 20 | ## 符合标准 21 | 22 | * RapidJSON 应完全符合 RFC4627/ECMA-404 标准。 23 | * 支持 JSON Pointer (RFC6901). 24 | * 支持 JSON Schema Draft v4. 25 | * 支持 Unicode 代理对(surrogate pair)。 26 | * 支持空字符(`"\u0000"`)。 27 | * 例如,可以优雅地解析及处理 `["Hello\u0000World"]`。含读写字符串长度的 API。 28 | * 支持可选的放宽语法 29 | * 单行(`// ...`)及多行(`/* ... */`) 注释 (`kParseCommentsFlag`)。 30 | * 在对象和数组结束前含逗号 (`kParseTrailingCommasFlag`)。 31 | * `NaN`、`Inf`、`Infinity`、`-Inf` 及 `-Infinity` 作为 `double` 值 (`kParseNanAndInfFlag`) 32 | * [NPM 兼容](https://github.com/Tencent/rapidjson/blob/master/doc/npm.md). 33 | 34 | ## Unicode 35 | 36 | * 支持 UTF-8、UTF-16、UTF-32 编码,包括小端序和大端序。 37 | * 这些编码用于输入输出流,以及内存中的表示。 38 | * 支持从输入流自动检测编码。 39 | * 内部支持编码的转换。 40 | * 例如,你可以读取一个 UTF-8 文件,让 RapidJSON 把 JSON 字符串转换至 UTF-16 的 DOM。 41 | * 内部支持编码校验。 42 | * 例如,你可以读取一个 UTF-8 文件,让 RapidJSON 检查是否所有 JSON 字符串是合法的 UTF-8 字节序列。 43 | * 支持自定义的字符类型。 44 | * 预设的字符类型是:UTF-8 为 `char`,UTF-16 为 `wchar_t`,UTF32 为 `uint32_t`。 45 | * 支持自定义的编码。 46 | 47 | ## API 风格 48 | 49 | * SAX(Simple API for XML)风格 API 50 | * 类似于 [SAX](http://en.wikipedia.org/wiki/Simple_API_for_XML), RapidJSON 提供一个事件循序访问的解析器 API(`rapidjson::GenericReader`)。RapidJSON 也提供一个生成器 API(`rapidjson::Writer`),可以处理相同的事件集合。 51 | * DOM(Document Object Model)风格 API 52 | * 类似于 HTML/XML 的 [DOM](http://en.wikipedia.org/wiki/Document_Object_Model),RapidJSON 可把 JSON 解析至一个 DOM 表示方式(`rapidjson::GenericDocument`),以方便操作。如有需要,可把 DOM 转换(stringify)回 JSON。 53 | * DOM 风格 API(`rapidjson::GenericDocument`)实际上是由 SAX 风格 API(`rapidjson::GenericReader`)实现的。SAX 更快,但有时 DOM 更易用。用户可根据情况作出选择。 54 | 55 | ## 解析 56 | 57 | * 递归式(预设)及迭代式解析器 58 | * 递归式解析器较快,但在极端情况下可出现堆栈溢出。 59 | * 迭代式解析器使用自定义的堆栈去维持解析状态。 60 | * 支持原位(*in situ*)解析。 61 | * 把 JSON 字符串的值解析至原 JSON 之中,然后让 DOM 指向那些字符串。 62 | * 比常规分析更快:不需字符串的内存分配、不需复制(如字符串不含转义符)、缓存友好。 63 | * 对于 JSON 数字类型,支持 32-bit/64-bit 的有号/无号整数,以及 `double`。 64 | * 错误处理 65 | * 支持详尽的解析错误代号。 66 | * 支持本地化错误信息。 67 | 68 | ## DOM (Document) 69 | 70 | * RapidJSON 在类型转换时会检查数值的范围。 71 | * 字符串字面量的优化 72 | * 只储存指针,不作复制 73 | * 优化“短”字符串 74 | * 在 `Value` 内储存短字符串,无需额外分配。 75 | * 对 UTF-8 字符串来说,32 位架构下可存储最多 11 字符,64 位下 21 字符(x86-64 下 13 字符)。 76 | * 可选地支持 `std::string`(定义 `RAPIDJSON_HAS_STDSTRING=1`) 77 | 78 | ## 生成 79 | 80 | * 支持 `rapidjson::PrettyWriter` 去加入换行及缩进。 81 | 82 | ## 输入输出流 83 | 84 | * 支持 `rapidjson::GenericStringBuffer`,把输出的 JSON 储存于字符串内。 85 | * 支持 `rapidjson::FileReadStream` 及 `rapidjson::FileWriteStream`,使用 `FILE` 对象作输入输出。 86 | * 支持自定义输入输出流。 87 | 88 | ## 内存 89 | 90 | * 最小化 DOM 的内存开销。 91 | * 对大部分 32/64 位机器而言,每个 JSON 值只占 16 或 20 字节(不包含字符串)。 92 | * 支持快速的预设分配器。 93 | * 它是一个堆栈形式的分配器(顺序分配,不容许单独释放,适合解析过程之用)。 94 | * 使用者也可提供一个预分配的缓冲区。(有可能达至无需 CRT 分配就能解析多个 JSON) 95 | * 支持标准 CRT(C-runtime)分配器。 96 | * 支持自定义分配器。 97 | 98 | ## 其他 99 | 100 | * 一些 C++11 的支持(可选) 101 | * 右值引用(rvalue reference) 102 | * `noexcept` 修饰符 103 | * 范围 for 循环 104 | -------------------------------------------------------------------------------- /doc/logo/rapidjson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/rapidjson/24b5e7a8b27f42fa16b96fc70aade9106cf7102f/doc/logo/rapidjson.png -------------------------------------------------------------------------------- /doc/misc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc/misc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 |
22 | $searchbox 23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/npm.md: -------------------------------------------------------------------------------- 1 | ## NPM 2 | 3 | # package.json {#package} 4 | 5 | ~~~~~~~~~~js 6 | { 7 | ... 8 | "dependencies": { 9 | ... 10 | "rapidjson": "git@github.com:Tencent/rapidjson.git" 11 | }, 12 | ... 13 | "gypfile": true 14 | } 15 | ~~~~~~~~~~ 16 | 17 | # binding.gyp {#binding} 18 | 19 | ~~~~~~~~~~js 20 | { 21 | ... 22 | 'targets': [ 23 | { 24 | ... 25 | 'include_dirs': [ 26 | ' 12 | #include 13 | 14 | using namespace rapidjson; 15 | 16 | template 17 | struct CapitalizeFilter { 18 | CapitalizeFilter(OutputHandler& out) : out_(out), buffer_() {} 19 | 20 | bool Null() { return out_.Null(); } 21 | bool Bool(bool b) { return out_.Bool(b); } 22 | bool Int(int i) { return out_.Int(i); } 23 | bool Uint(unsigned u) { return out_.Uint(u); } 24 | bool Int64(int64_t i) { return out_.Int64(i); } 25 | bool Uint64(uint64_t u) { return out_.Uint64(u); } 26 | bool Double(double d) { return out_.Double(d); } 27 | bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); } 28 | bool String(const char* str, SizeType length, bool) { 29 | buffer_.clear(); 30 | for (SizeType i = 0; i < length; i++) 31 | buffer_.push_back(static_cast(std::toupper(str[i]))); 32 | return out_.String(&buffer_.front(), length, true); // true = output handler need to copy the string 33 | } 34 | bool StartObject() { return out_.StartObject(); } 35 | bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); } 36 | bool EndObject(SizeType memberCount) { return out_.EndObject(memberCount); } 37 | bool StartArray() { return out_.StartArray(); } 38 | bool EndArray(SizeType elementCount) { return out_.EndArray(elementCount); } 39 | 40 | OutputHandler& out_; 41 | std::vector buffer_; 42 | 43 | private: 44 | CapitalizeFilter(const CapitalizeFilter&); 45 | CapitalizeFilter& operator=(const CapitalizeFilter&); 46 | }; 47 | 48 | int main(int, char*[]) { 49 | // Prepare JSON reader and input stream. 50 | Reader reader; 51 | char readBuffer[65536]; 52 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 53 | 54 | // Prepare JSON writer and output stream. 55 | char writeBuffer[65536]; 56 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 57 | Writer writer(os); 58 | 59 | // JSON reader parse from the input stream and let writer generate the output. 60 | CapitalizeFilter > filter(writer); 61 | if (!reader.Parse(is, filter)) { 62 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 63 | return 1; 64 | } 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /example/condense/condense.cpp: -------------------------------------------------------------------------------- 1 | // JSON condenser example 2 | 3 | // This example parses JSON text from stdin with validation, 4 | // and re-output the JSON content to stdout without whitespace. 5 | 6 | #include "rapidjson/reader.h" 7 | #include "rapidjson/writer.h" 8 | #include "rapidjson/filereadstream.h" 9 | #include "rapidjson/filewritestream.h" 10 | #include "rapidjson/error/en.h" 11 | 12 | using namespace rapidjson; 13 | 14 | int main(int, char*[]) { 15 | // Prepare JSON reader and input stream. 16 | Reader reader; 17 | char readBuffer[65536]; 18 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 19 | 20 | // Prepare JSON writer and output stream. 21 | char writeBuffer[65536]; 22 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 23 | Writer writer(os); 24 | 25 | // JSON reader parse from the input stream and let writer generate the output. 26 | if (!reader.Parse(is, writer)) { 27 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 28 | return 1; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /example/messagereader/messagereader.cpp: -------------------------------------------------------------------------------- 1 | // Reading a message JSON with Reader (SAX-style API). 2 | // The JSON should be an object with key-string pairs. 3 | 4 | #include "rapidjson/reader.h" 5 | #include "rapidjson/error/en.h" 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace rapidjson; 12 | 13 | typedef map MessageMap; 14 | 15 | #if defined(__GNUC__) 16 | RAPIDJSON_DIAG_PUSH 17 | RAPIDJSON_DIAG_OFF(effc++) 18 | #endif 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | #endif 24 | 25 | struct MessageHandler 26 | : public BaseReaderHandler, MessageHandler> { 27 | MessageHandler() : messages_(), state_(kExpectObjectStart), name_() {} 28 | 29 | bool StartObject() { 30 | switch (state_) { 31 | case kExpectObjectStart: 32 | state_ = kExpectNameOrObjectEnd; 33 | return true; 34 | default: 35 | return false; 36 | } 37 | } 38 | 39 | bool String(const char* str, SizeType length, bool) { 40 | switch (state_) { 41 | case kExpectNameOrObjectEnd: 42 | name_ = string(str, length); 43 | state_ = kExpectValue; 44 | return true; 45 | case kExpectValue: 46 | messages_.insert(MessageMap::value_type(name_, string(str, length))); 47 | state_ = kExpectNameOrObjectEnd; 48 | return true; 49 | default: 50 | return false; 51 | } 52 | } 53 | 54 | bool EndObject(SizeType) { return state_ == kExpectNameOrObjectEnd; } 55 | 56 | bool Default() { return false; } // All other events are invalid. 57 | 58 | MessageMap messages_; 59 | enum State { 60 | kExpectObjectStart, 61 | kExpectNameOrObjectEnd, 62 | kExpectValue 63 | }state_; 64 | std::string name_; 65 | }; 66 | 67 | #if defined(__GNUC__) 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #ifdef __clang__ 72 | RAPIDJSON_DIAG_POP 73 | #endif 74 | 75 | static void ParseMessages(const char* json, MessageMap& messages) { 76 | Reader reader; 77 | MessageHandler handler; 78 | StringStream ss(json); 79 | if (reader.Parse(ss, handler)) 80 | messages.swap(handler.messages_); // Only change it if success. 81 | else { 82 | ParseErrorCode e = reader.GetParseErrorCode(); 83 | size_t o = reader.GetErrorOffset(); 84 | cout << "Error: " << GetParseError_En(e) << endl;; 85 | cout << " at offset " << o << " near '" << string(json).substr(o, 10) << "...'" << endl; 86 | } 87 | } 88 | 89 | int main() { 90 | MessageMap messages; 91 | 92 | const char* json1 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\" }"; 93 | cout << json1 << endl; 94 | ParseMessages(json1, messages); 95 | 96 | for (MessageMap::const_iterator itr = messages.begin(); itr != messages.end(); ++itr) 97 | cout << itr->first << ": " << itr->second << endl; 98 | 99 | cout << endl << "Parse a JSON with invalid schema." << endl; 100 | const char* json2 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\", \"foo\" : {} }"; 101 | cout << json2 << endl; 102 | ParseMessages(json2, messages); 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /example/pretty/pretty.cpp: -------------------------------------------------------------------------------- 1 | // JSON pretty formatting example 2 | // This example can only handle UTF-8. For handling other encodings, see prettyauto example. 3 | 4 | #include "rapidjson/reader.h" 5 | #include "rapidjson/prettywriter.h" 6 | #include "rapidjson/filereadstream.h" 7 | #include "rapidjson/filewritestream.h" 8 | #include "rapidjson/error/en.h" 9 | 10 | using namespace rapidjson; 11 | 12 | int main(int, char*[]) { 13 | // Prepare reader and input stream. 14 | Reader reader; 15 | char readBuffer[65536]; 16 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 17 | 18 | // Prepare writer and output stream. 19 | char writeBuffer[65536]; 20 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 21 | PrettyWriter writer(os); 22 | 23 | // JSON reader parse from the input stream and let writer generate the output. 24 | if (!reader.Parse(is, writer)) { 25 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 26 | return 1; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /example/prettyauto/prettyauto.cpp: -------------------------------------------------------------------------------- 1 | // JSON pretty formatting example 2 | // This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE. 3 | // The input firstly convert to UTF8, and then write to the original encoding with pretty formatting. 4 | 5 | #include "rapidjson/reader.h" 6 | #include "rapidjson/prettywriter.h" 7 | #include "rapidjson/filereadstream.h" 8 | #include "rapidjson/filewritestream.h" 9 | #include "rapidjson/encodedstream.h" // NEW 10 | #include "rapidjson/error/en.h" 11 | #ifdef _WIN32 12 | #include 13 | #include 14 | #endif 15 | 16 | using namespace rapidjson; 17 | 18 | int main(int, char*[]) { 19 | #ifdef _WIN32 20 | // Prevent Windows converting between CR+LF and LF 21 | _setmode(_fileno(stdin), _O_BINARY); // NEW 22 | _setmode(_fileno(stdout), _O_BINARY); // NEW 23 | #endif 24 | 25 | // Prepare reader and input stream. 26 | //Reader reader; 27 | GenericReader, UTF8<> > reader; // CHANGED 28 | char readBuffer[65536]; 29 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 30 | AutoUTFInputStream eis(is); // NEW 31 | 32 | // Prepare writer and output stream. 33 | char writeBuffer[65536]; 34 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 35 | 36 | #if 1 37 | // Use the same Encoding of the input. Also use BOM according to input. 38 | typedef AutoUTFOutputStream OutputStream; // NEW 39 | OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW 40 | PrettyWriter, AutoUTF > writer(eos); // CHANGED 41 | #else 42 | // You may also use static bound encoding type, such as output to UTF-16LE with BOM 43 | typedef EncodedOutputStream,FileWriteStream> OutputStream; // NEW 44 | OutputStream eos(os, true); // NEW 45 | PrettyWriter, UTF16LE<> > writer(eos); // CHANGED 46 | #endif 47 | 48 | // JSON reader parse from the input stream and let writer generate the output. 49 | //if (!reader.Parse(is, writer)) { 50 | if (!reader.Parse(eis, writer)) { // CHANGED 51 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 52 | return 1; 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /example/simpledom/simpledom.cpp: -------------------------------------------------------------------------------- 1 | // JSON simple example 2 | // This example does not handle errors. 3 | 4 | #include "rapidjson/document.h" 5 | #include "rapidjson/writer.h" 6 | #include "rapidjson/stringbuffer.h" 7 | #include 8 | 9 | using namespace rapidjson; 10 | 11 | int main() { 12 | // 1. Parse a JSON string into DOM. 13 | const char* json = "{\"project\":\"rapidjson\",\"stars\":10}"; 14 | Document d; 15 | d.Parse(json); 16 | 17 | // 2. Modify it by DOM. 18 | Value& s = d["stars"]; 19 | s.SetInt(s.GetInt() + 1); 20 | 21 | // 3. Stringify the DOM 22 | StringBuffer buffer; 23 | Writer writer(buffer); 24 | d.Accept(writer); 25 | 26 | // Output {"project":"rapidjson","stars":11} 27 | std::cout << buffer.GetString() << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /example/simplepullreader/simplepullreader.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/reader.h" 2 | #include 3 | #include 4 | 5 | using namespace rapidjson; 6 | using namespace std; 7 | 8 | // If you can require C++11, you could use std::to_string here 9 | template std::string stringify(T x) { 10 | std::stringstream ss; 11 | ss << x; 12 | return ss.str(); 13 | } 14 | 15 | struct MyHandler { 16 | const char* type; 17 | std::string data; 18 | 19 | MyHandler() : type(), data() {} 20 | 21 | bool Null() { type = "Null"; data.clear(); return true; } 22 | bool Bool(bool b) { type = "Bool:"; data = b? "true": "false"; return true; } 23 | bool Int(int i) { type = "Int:"; data = stringify(i); return true; } 24 | bool Uint(unsigned u) { type = "Uint:"; data = stringify(u); return true; } 25 | bool Int64(int64_t i) { type = "Int64:"; data = stringify(i); return true; } 26 | bool Uint64(uint64_t u) { type = "Uint64:"; data = stringify(u); return true; } 27 | bool Double(double d) { type = "Double:"; data = stringify(d); return true; } 28 | bool RawNumber(const char* str, SizeType length, bool) { type = "Number:"; data = std::string(str, length); return true; } 29 | bool String(const char* str, SizeType length, bool) { type = "String:"; data = std::string(str, length); return true; } 30 | bool StartObject() { type = "StartObject"; data.clear(); return true; } 31 | bool Key(const char* str, SizeType length, bool) { type = "Key:"; data = std::string(str, length); return true; } 32 | bool EndObject(SizeType memberCount) { type = "EndObject:"; data = stringify(memberCount); return true; } 33 | bool StartArray() { type = "StartArray"; data.clear(); return true; } 34 | bool EndArray(SizeType elementCount) { type = "EndArray:"; data = stringify(elementCount); return true; } 35 | private: 36 | MyHandler(const MyHandler& noCopyConstruction); 37 | MyHandler& operator=(const MyHandler& noAssignment); 38 | }; 39 | 40 | int main() { 41 | const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; 42 | 43 | MyHandler handler; 44 | Reader reader; 45 | StringStream ss(json); 46 | reader.IterativeParseInit(); 47 | while (!reader.IterativeParseComplete()) { 48 | reader.IterativeParseNext(ss, handler); 49 | cout << handler.type << handler.data << endl; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /example/simplereader/simplereader.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/reader.h" 2 | #include 3 | 4 | using namespace rapidjson; 5 | using namespace std; 6 | 7 | struct MyHandler { 8 | bool Null() { cout << "Null()" << endl; return true; } 9 | bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; } 10 | bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; } 11 | bool Uint(unsigned u) { cout << "Uint(" << u << ")" << endl; return true; } 12 | bool Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; return true; } 13 | bool Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; } 14 | bool Double(double d) { cout << "Double(" << d << ")" << endl; return true; } 15 | bool RawNumber(const char* str, SizeType length, bool copy) { 16 | cout << "Number(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 17 | return true; 18 | } 19 | bool String(const char* str, SizeType length, bool copy) { 20 | cout << "String(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 21 | return true; 22 | } 23 | bool StartObject() { cout << "StartObject()" << endl; return true; } 24 | bool Key(const char* str, SizeType length, bool copy) { 25 | cout << "Key(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 26 | return true; 27 | } 28 | bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; } 29 | bool StartArray() { cout << "StartArray()" << endl; return true; } 30 | bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; } 31 | }; 32 | 33 | int main() { 34 | const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; 35 | 36 | MyHandler handler; 37 | Reader reader; 38 | StringStream ss(json); 39 | reader.Parse(ss, handler); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /example/simplewriter/simplewriter.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/writer.h" 2 | #include "rapidjson/stringbuffer.h" 3 | #include 4 | 5 | using namespace rapidjson; 6 | using namespace std; 7 | 8 | int main() { 9 | StringBuffer s; 10 | Writer writer(s); 11 | 12 | writer.StartObject(); // Between StartObject()/EndObject(), 13 | writer.Key("hello"); // output a key, 14 | writer.String("world"); // follow by a value. 15 | writer.Key("t"); 16 | writer.Bool(true); 17 | writer.Key("f"); 18 | writer.Bool(false); 19 | writer.Key("n"); 20 | writer.Null(); 21 | writer.Key("i"); 22 | writer.Uint(123); 23 | writer.Key("pi"); 24 | writer.Double(3.1416); 25 | writer.Key("a"); 26 | writer.StartArray(); // Between StartArray()/EndArray(), 27 | for (unsigned i = 0; i < 4; i++) 28 | writer.Uint(i); // all values are elements of the array. 29 | writer.EndArray(); 30 | writer.EndObject(); 31 | 32 | // {"hello":"world","t":true,"f":false,"n":null,"i":123,"pi":3.1416,"a":[0,1,2,3]} 33 | cout << s.GetString() << endl; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /example/sortkeys/sortkeys.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/document.h" 2 | #include "rapidjson/filewritestream.h" 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | using namespace rapidjson; 9 | using namespace std; 10 | 11 | static void printIt(const Value &doc) { 12 | char writeBuffer[65536]; 13 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 14 | PrettyWriter writer(os); 15 | doc.Accept(writer); 16 | cout << endl; 17 | } 18 | 19 | struct NameComparator { 20 | bool operator()(const Value::Member &lhs, const Value::Member &rhs) const { 21 | return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); 22 | } 23 | }; 24 | 25 | int main() { 26 | Document d(kObjectType); 27 | Document::AllocatorType &allocator = d.GetAllocator(); 28 | 29 | d.AddMember("zeta", Value().SetBool(false), allocator); 30 | d.AddMember("gama", Value().SetString("test string", allocator), allocator); 31 | d.AddMember("delta", Value().SetInt(123), allocator); 32 | d.AddMember("alpha", Value(kArrayType).Move(), allocator); 33 | 34 | printIt(d); 35 | 36 | /* 37 | { 38 | "zeta": false, 39 | "gama": "test string", 40 | "delta": 123, 41 | "alpha": [] 42 | } 43 | */ 44 | 45 | // C++11 supports std::move() of Value so it always have no problem for std::sort(). 46 | // Some C++03 implementations of std::sort() requires copy constructor which causes compilation error. 47 | // Needs a sorting function only depends on std::swap() instead. 48 | #if __cplusplus >= 201103L || (!defined(__GLIBCXX__) && (!defined(_MSC_VER) || _MSC_VER >= 1900)) 49 | std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator()); 50 | 51 | printIt(d); 52 | 53 | /* 54 | { 55 | "alpha": [], 56 | "delta": 123, 57 | "gama": "test string", 58 | "zeta": false 59 | } 60 | */ 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /example/traverseaspointer.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/document.h" 2 | #include "rapidjson/filereadstream.h" 3 | #include "rapidjson/pointer.h" 4 | #include "rapidjson/stringbuffer.h" 5 | #include 6 | 7 | using namespace rapidjson; 8 | 9 | void traverse(const Value& v, const Pointer& p) { 10 | StringBuffer sb; 11 | p.Stringify(sb); 12 | std::cout << sb.GetString() << std::endl; 13 | 14 | switch (v.GetType()) { 15 | case kArrayType: 16 | for (SizeType i = 0; i != v.Size(); ++i) 17 | traverse(v[i], p.Append(i)); 18 | break; 19 | case kObjectType: 20 | for (Value::ConstMemberIterator m = v.MemberBegin(); m != v.MemberEnd(); ++m) 21 | traverse(m->value, p.Append(m->name.GetString(), m->name.GetStringLength())); 22 | break; 23 | default: 24 | break; 25 | } 26 | } 27 | 28 | int main(int, char*[]) { 29 | char readBuffer[65536]; 30 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 31 | 32 | Document d; 33 | d.ParseStream(is); 34 | 35 | Pointer root; 36 | traverse(d, root); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /include/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 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. 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_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /include/rapidjson/filereadstream.h: -------------------------------------------------------------------------------- 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. 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_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /include/rapidjson/internal/clzll.h: -------------------------------------------------------------------------------- 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. 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_CLZLL_H_ 16 | #define RAPIDJSON_CLZLL_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && !defined(UNDER_CE) 21 | #include 22 | #if defined(_WIN64) 23 | #pragma intrinsic(_BitScanReverse64) 24 | #else 25 | #pragma intrinsic(_BitScanReverse) 26 | #endif 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | namespace internal { 31 | 32 | inline uint32_t clzll(uint64_t x) { 33 | // Passing 0 to __builtin_clzll is UB in GCC and results in an 34 | // infinite loop in the software implementation. 35 | RAPIDJSON_ASSERT(x != 0); 36 | 37 | #if defined(_MSC_VER) && !defined(UNDER_CE) 38 | unsigned long r = 0; 39 | #if defined(_WIN64) 40 | _BitScanReverse64(&r, x); 41 | #else 42 | // Scan the high 32 bits. 43 | if (_BitScanReverse(&r, static_cast(x >> 32))) 44 | return 63 - (r + 32); 45 | 46 | // Scan the low 32 bits. 47 | _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); 48 | #endif // _WIN64 49 | 50 | return 63 - r; 51 | #elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 52 | // __builtin_clzll wrapper 53 | return static_cast(__builtin_clzll(x)); 54 | #else 55 | // naive version 56 | uint32_t r = 0; 57 | while (!(x & (static_cast(1) << 63))) { 58 | x <<= 1; 59 | ++r; 60 | } 61 | 62 | return r; 63 | #endif // _MSC_VER 64 | } 65 | 66 | #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll 67 | 68 | } // namespace internal 69 | RAPIDJSON_NAMESPACE_END 70 | 71 | #endif // RAPIDJSON_CLZLL_H_ 72 | -------------------------------------------------------------------------------- /include/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 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. 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_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /include/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 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. 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_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Custom strcmpn() which works on different character types. 49 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 50 | \param s1 Null-terminated input string. 51 | \param s2 Null-terminated input string. 52 | \return 0 if equal 53 | */ 54 | template 55 | inline int StrCmp(const Ch* s1, const Ch* s2) { 56 | RAPIDJSON_ASSERT(s1 != 0); 57 | RAPIDJSON_ASSERT(s2 != 0); 58 | while(*s1 && (*s1 == *s2)) { s1++; s2++; } 59 | return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); 60 | } 61 | 62 | //! Returns number of code points in a encoded string. 63 | template 64 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 65 | RAPIDJSON_ASSERT(s != 0); 66 | RAPIDJSON_ASSERT(outCount != 0); 67 | GenericStringStream is(s); 68 | const typename Encoding::Ch* end = s + length; 69 | SizeType count = 0; 70 | while (is.src_ < end) { 71 | unsigned codepoint; 72 | if (!Encoding::Decode(is, &codepoint)) 73 | return false; 74 | count++; 75 | } 76 | *outCount = count; 77 | return true; 78 | } 79 | 80 | } // namespace internal 81 | RAPIDJSON_NAMESPACE_END 82 | 83 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 84 | -------------------------------------------------------------------------------- /include/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 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. 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_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /include/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 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. 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_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /include/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 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. 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_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /include/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 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. 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_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /include_dirs.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | console.log(path.join(path.relative('.', __dirname), 'include')); 3 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RapidJSON", 3 | "version": "1.1.0", 4 | "keywords": "json, sax, dom, parser, generator", 5 | "description": "A fast JSON parser/generator for C++ with both SAX/DOM style API", 6 | "export": { 7 | "include": "include" 8 | }, 9 | "examples": "example/*/*.cpp", 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/Tencent/rapidjson" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rapidjson", 3 | "version": "1.0.4", 4 | "description": "![](doc/logo/rapidjson.png)", 5 | "main": "include_dirs.js", 6 | "directories": { 7 | "doc": "doc", 8 | "example": "example", 9 | "test": "test" 10 | }, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/Tencent/rapidjson.git" 17 | }, 18 | "author": "", 19 | "license": "ISC", 20 | "bugs": { 21 | "url": "https://github.com/Tencent/rapidjson/issues" 22 | }, 23 | "homepage": "https://github.com/Tencent/rapidjson#readme" 24 | } 25 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(GTestSrc) 2 | 3 | IF(GTESTSRC_FOUND) 4 | enable_testing() 5 | 6 | if (WIN32 AND (NOT CYGWIN) AND (NOT MINGW)) 7 | set(gtest_disable_pthreads ON) 8 | set(gtest_force_shared_crt ON) 9 | endif() 10 | 11 | add_subdirectory(${GTEST_SOURCE_DIR} ${CMAKE_BINARY_DIR}/googletest) 12 | include_directories(SYSTEM ${GTEST_INCLUDE_DIR}) 13 | 14 | set(TEST_LIBRARIES gtest gtest_main) 15 | 16 | add_custom_target(tests ALL) 17 | add_subdirectory(perftest) 18 | add_subdirectory(unittest) 19 | 20 | ENDIF(GTESTSRC_FOUND) 21 | -------------------------------------------------------------------------------- /test/perftest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PERFTEST_SOURCES 2 | misctest.cpp 3 | perftest.cpp 4 | platformtest.cpp 5 | rapidjsontest.cpp 6 | schematest.cpp) 7 | 8 | add_executable(perftest ${PERFTEST_SOURCES}) 9 | target_link_libraries(perftest ${TEST_LIBRARIES}) 10 | 11 | add_dependencies(tests perftest) 12 | 13 | find_program(CCACHE_FOUND ccache) 14 | if(CCACHE_FOUND) 15 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 16 | set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) 17 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 18 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") 19 | endif() 20 | endif(CCACHE_FOUND) 21 | 22 | set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) 23 | 24 | IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) 25 | add_test(NAME perftest 26 | COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest 27 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 28 | ENDIF() 29 | -------------------------------------------------------------------------------- /test/perftest/perftest.cpp: -------------------------------------------------------------------------------- 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. 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 "perftest.h" 16 | 17 | int main(int argc, char **argv) { 18 | #if _MSC_VER 19 | _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 20 | //void *testWhetherMemoryLeakDetectionWorks = malloc(1); 21 | #endif 22 | ::testing::InitGoogleTest(&argc, argv); 23 | return RUN_ALL_TESTS(); 24 | } 25 | -------------------------------------------------------------------------------- /test/unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckCXXCompilerFlag) 2 | 3 | set(UNITTEST_SOURCES 4 | allocatorstest.cpp 5 | bigintegertest.cpp 6 | clzlltest.cpp 7 | cursorstreamwrappertest.cpp 8 | documenttest.cpp 9 | dtoatest.cpp 10 | encodedstreamtest.cpp 11 | encodingstest.cpp 12 | fwdtest.cpp 13 | filestreamtest.cpp 14 | itoatest.cpp 15 | istreamwrappertest.cpp 16 | jsoncheckertest.cpp 17 | namespacetest.cpp 18 | pointertest.cpp 19 | platformtest.cpp 20 | prettywritertest.cpp 21 | ostreamwrappertest.cpp 22 | readertest.cpp 23 | regextest.cpp 24 | schematest.cpp 25 | simdtest.cpp 26 | strfunctest.cpp 27 | stringbuffertest.cpp 28 | strtodtest.cpp 29 | unittest.cpp 30 | uritest.cpp 31 | valuetest.cpp 32 | writertest.cpp) 33 | 34 | find_program(CCACHE_FOUND ccache) 35 | if(CCACHE_FOUND) 36 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 37 | set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) 38 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 39 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") 40 | endif() 41 | endif(CCACHE_FOUND) 42 | 43 | set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) 44 | 45 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 46 | # If the user is running a newer version of Clang that includes the 47 | # -Wdouble-promotion, we will ignore that warning. 48 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.7) 49 | CHECK_CXX_COMPILER_FLAG("-Wno-double-promotion" HAS_NO_DOUBLE_PROMOTION) 50 | if (HAS_NO_DOUBLE_PROMOTION) 51 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion") 52 | endif() 53 | endif() 54 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 55 | # Force to always compile with /W4 56 | if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 57 | string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 58 | else() 59 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") 60 | endif() 61 | 62 | # Force to always compile with /WX 63 | if(CMAKE_CXX_FLAGS MATCHES "/WX-") 64 | string(REGEX REPLACE "/WX-" "/WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 65 | else() 66 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") 67 | endif() 68 | endif() 69 | 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRAPIDJSON_HAS_STDSTRING=1") 71 | 72 | add_library(namespacetest STATIC namespacetest.cpp) 73 | 74 | add_executable(unittest ${UNITTEST_SOURCES}) 75 | target_link_libraries(unittest ${TEST_LIBRARIES} namespacetest) 76 | 77 | add_dependencies(tests unittest) 78 | 79 | add_test(NAME unittest 80 | COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest 81 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 82 | 83 | if(NOT MSVC AND VALGRIND_FOUND) 84 | # Not running SIMD.* unit test cases for Valgrind 85 | add_test(NAME valgrind_unittest 86 | COMMAND valgrind --suppressions=${CMAKE_SOURCE_DIR}/test/valgrind.supp --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest --gtest_filter=-SIMD.* 87 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 88 | 89 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 90 | add_test(NAME symbol_check 91 | COMMAND sh -c "objdump -t -C libnamespacetest.a | grep rapidjson ; test $? -ne 0" 92 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 93 | endif(CMAKE_BUILD_TYPE STREQUAL "Debug") 94 | 95 | endif(NOT MSVC AND VALGRIND_FOUND) 96 | -------------------------------------------------------------------------------- /test/unittest/clzlltest.cpp: -------------------------------------------------------------------------------- 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. 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 "unittest.h" 16 | #include "rapidjson/internal/clzll.h" 17 | 18 | #ifdef __GNUC__ 19 | RAPIDJSON_DIAG_PUSH 20 | #endif 21 | 22 | using namespace rapidjson::internal; 23 | 24 | TEST(clzll, normal) { 25 | EXPECT_EQ(clzll(1), 63U); 26 | EXPECT_EQ(clzll(2), 62U); 27 | EXPECT_EQ(clzll(12), 60U); 28 | EXPECT_EQ(clzll(0x0000000080000001UL), 32U); 29 | EXPECT_EQ(clzll(0x8000000000000001UL), 0U); 30 | } 31 | 32 | #ifdef __GNUC__ 33 | RAPIDJSON_DIAG_POP 34 | #endif 35 | -------------------------------------------------------------------------------- /test/unittest/namespacetest.cpp: -------------------------------------------------------------------------------- 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. 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 "unittest.h" 16 | 17 | // test another instantiation of RapidJSON in a different namespace 18 | 19 | #define RAPIDJSON_NAMESPACE my::rapid::json 20 | #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapid { namespace json { 21 | #define RAPIDJSON_NAMESPACE_END } } } 22 | 23 | // include lots of RapidJSON files 24 | 25 | #include "rapidjson/document.h" 26 | #include "rapidjson/writer.h" 27 | #include "rapidjson/filereadstream.h" 28 | #include "rapidjson/filewritestream.h" 29 | #include "rapidjson/encodedstream.h" 30 | #include "rapidjson/stringbuffer.h" 31 | 32 | static const char json[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}"; 33 | 34 | TEST(NamespaceTest,Using) { 35 | using namespace RAPIDJSON_NAMESPACE; 36 | typedef GenericDocument, CrtAllocator> DocumentType; 37 | DocumentType doc; 38 | 39 | doc.Parse(json); 40 | EXPECT_TRUE(!doc.HasParseError()); 41 | } 42 | 43 | TEST(NamespaceTest,Direct) { 44 | typedef RAPIDJSON_NAMESPACE::Document Document; 45 | typedef RAPIDJSON_NAMESPACE::Reader Reader; 46 | typedef RAPIDJSON_NAMESPACE::StringStream StringStream; 47 | typedef RAPIDJSON_NAMESPACE::StringBuffer StringBuffer; 48 | typedef RAPIDJSON_NAMESPACE::Writer WriterType; 49 | 50 | StringStream s(json); 51 | StringBuffer buffer; 52 | WriterType writer(buffer); 53 | buffer.ShrinkToFit(); 54 | Reader reader; 55 | reader.Parse(s, writer); 56 | 57 | EXPECT_STREQ(json, buffer.GetString()); 58 | EXPECT_EQ(sizeof(json)-1, buffer.GetSize()); 59 | EXPECT_TRUE(writer.IsComplete()); 60 | 61 | Document doc; 62 | doc.Parse(buffer.GetString()); 63 | EXPECT_TRUE(!doc.HasParseError()); 64 | 65 | buffer.Clear(); 66 | writer.Reset(buffer); 67 | doc.Accept(writer); 68 | EXPECT_STREQ(json, buffer.GetString()); 69 | EXPECT_TRUE(writer.IsComplete()); 70 | } 71 | -------------------------------------------------------------------------------- /test/unittest/ostreamwrappertest.cpp: -------------------------------------------------------------------------------- 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. 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 "unittest.h" 16 | 17 | #include "rapidjson/ostreamwrapper.h" 18 | #include "rapidjson/encodedstream.h" 19 | #include "rapidjson/document.h" 20 | #include 21 | #include 22 | 23 | using namespace rapidjson; 24 | using namespace std; 25 | 26 | template 27 | static void TestStringStream() { 28 | typedef typename StringStreamType::char_type Ch; 29 | 30 | Ch s[] = { 'A', 'B', 'C', '\0' }; 31 | StringStreamType oss(s); 32 | BasicOStreamWrapper os(oss); 33 | for (size_t i = 0; i < 3; i++) 34 | os.Put(s[i]); 35 | os.Flush(); 36 | for (size_t i = 0; i < 3; i++) 37 | EXPECT_EQ(s[i], oss.str()[i]); 38 | } 39 | 40 | TEST(OStreamWrapper, ostringstream) { 41 | TestStringStream(); 42 | } 43 | 44 | TEST(OStreamWrapper, stringstream) { 45 | TestStringStream(); 46 | } 47 | 48 | TEST(OStreamWrapper, wostringstream) { 49 | TestStringStream(); 50 | } 51 | 52 | TEST(OStreamWrapper, wstringstream) { 53 | TestStringStream(); 54 | } 55 | 56 | TEST(OStreamWrapper, cout) { 57 | OStreamWrapper os(cout); 58 | const char* s = "Hello World!\n"; 59 | while (*s) 60 | os.Put(*s++); 61 | os.Flush(); 62 | } 63 | 64 | template 65 | static void TestFileStream() { 66 | char filename[L_tmpnam]; 67 | FILE* fp = TempFile(filename); 68 | fclose(fp); 69 | 70 | const char* s = "Hello World!\n"; 71 | { 72 | FileStreamType ofs(filename, ios::out | ios::binary); 73 | BasicOStreamWrapper osw(ofs); 74 | for (const char* p = s; *p; p++) 75 | osw.Put(*p); 76 | osw.Flush(); 77 | } 78 | 79 | fp = fopen(filename, "r"); 80 | ASSERT_TRUE( fp != NULL ); 81 | for (const char* p = s; *p; p++) 82 | EXPECT_EQ(*p, static_cast(fgetc(fp))); 83 | fclose(fp); 84 | } 85 | 86 | TEST(OStreamWrapper, ofstream) { 87 | TestFileStream(); 88 | } 89 | 90 | TEST(OStreamWrapper, fstream) { 91 | TestFileStream(); 92 | } 93 | -------------------------------------------------------------------------------- /test/unittest/platformtest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company, and Milo Yip. 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 "unittest.h" 16 | 17 | // see https://github.com/Tencent/rapidjson/issues/1448 18 | // including windows.h on purpose to provoke a compile time problem as GetObject is a 19 | // macro that gets defined when windows.h is included 20 | #ifdef _WIN32 21 | #include 22 | #endif 23 | 24 | #include "rapidjson/document.h" 25 | #undef GetObject 26 | 27 | using namespace rapidjson; 28 | 29 | TEST(Platform, GetObject) { 30 | Document doc; 31 | doc.Parse(" { \"object\" : { \"pi\": 3.1416} } "); 32 | EXPECT_TRUE(doc.IsObject()); 33 | EXPECT_TRUE(doc.HasMember("object")); 34 | const Document::ValueType& o = doc["object"]; 35 | EXPECT_TRUE(o.IsObject()); 36 | Value::ConstObject sub = o.GetObject(); 37 | EXPECT_TRUE(sub.HasMember("pi")); 38 | Value::ConstObject sub2 = o.GetObj(); 39 | EXPECT_TRUE(sub2.HasMember("pi")); 40 | } 41 | -------------------------------------------------------------------------------- /test/unittest/strfunctest.cpp: -------------------------------------------------------------------------------- 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. 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 "unittest.h" 16 | #include "rapidjson/internal/strfunc.h" 17 | 18 | using namespace rapidjson; 19 | using namespace rapidjson::internal; 20 | 21 | TEST(StrFunc, CountStringCodePoint) { 22 | SizeType count; 23 | EXPECT_TRUE(CountStringCodePoint >("", 0, &count)); 24 | EXPECT_EQ(0u, count); 25 | EXPECT_TRUE(CountStringCodePoint >("Hello", 5, &count)); 26 | EXPECT_EQ(5u, count); 27 | EXPECT_TRUE(CountStringCodePoint >("\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E", 9, &count)); // cents euro G-clef 28 | EXPECT_EQ(3u, count); 29 | EXPECT_FALSE(CountStringCodePoint >("\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E\x80", 10, &count)); 30 | } 31 | -------------------------------------------------------------------------------- /test/unittest/unittest.cpp: -------------------------------------------------------------------------------- 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. 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 "unittest.h" 16 | #include "rapidjson/rapidjson.h" 17 | 18 | #ifdef __clang__ 19 | #pragma GCC diagnostic push 20 | #if __has_warning("-Wdeprecated") 21 | #pragma GCC diagnostic ignored "-Wdeprecated" 22 | #endif 23 | #endif 24 | 25 | AssertException::~AssertException() throw() {} 26 | 27 | #ifdef __clang__ 28 | #pragma GCC diagnostic pop 29 | #endif 30 | 31 | int main(int argc, char **argv) { 32 | ::testing::InitGoogleTest(&argc, argv); 33 | 34 | std::cout << "RapidJSON v" << RAPIDJSON_VERSION_STRING << std::endl; 35 | 36 | #ifdef _MSC_VER 37 | _CrtMemState memoryState = { 0 }; 38 | (void)memoryState; 39 | _CrtMemCheckpoint(&memoryState); 40 | //_CrtSetBreakAlloc(X); 41 | //void *testWhetherMemoryLeakDetectionWorks = malloc(1); 42 | #endif 43 | 44 | int ret = RUN_ALL_TESTS(); 45 | 46 | #ifdef _MSC_VER 47 | // Current gtest constantly leak 2 blocks at exit 48 | _CrtMemDumpAllObjectsSince(&memoryState); 49 | #endif 50 | return ret; 51 | } 52 | -------------------------------------------------------------------------------- /test/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | Suppress wcslen valgrind report 1 3 | Memcheck:Cond 4 | fun:__wcslen_sse2 5 | } 6 | 7 | { 8 | Suppress wcslen valgrind report 2 9 | Memcheck:Addr8 10 | fun:__wcslen_sse2 11 | } 12 | 13 | { 14 | Suppress wcslen valgrind report 3 15 | Memcheck:Value8 16 | fun:__wcslen_sse2 17 | } 18 | 19 | { 20 | Suppress wmemcmp valgrind report 4 21 | Memcheck:Addr32 22 | fun:__wmemcmp_avx2_movbe 23 | ... 24 | fun:*Uri*Parse_UTF16_Std* 25 | } 26 | 27 | --------------------------------------------------------------------------------