Repository navigation
Add more codes in it - #188
Open
MedChronicle wants to merge 2 commits into
Open
Add more codes in it #188MedChronicle wants to merge 2 commits into
MedChronicle wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add extension helpers: typed getters, string decoding, counting/iteration, depth, minify and prettify
Description
Adds a new optional extension module (
core_json_ext.c/core_json_ext.h) on top of the public coreJSON API.core_json.candcore_json.hare not modified. The module uses onlyJSON_Validate,JSON_SearchConstandJSON_Iterate, and never allocates memory (the caller supplies all output buffers).New functions:
JSON_GetInt,JSON_GetDouble,JSON_GetBool: typed getters with type and overflow checks (LLONG_MINhandled correctly).JSON_GetString: decodes escapes (\n,\",\uXXXXincluding surrogate pairs) to UTF-8 and NUL-terminates. Rejects\u0000.JSON_Exists,JSON_GetType: check whether a key exists and what type it is.JSON_Count,JSON_ForEach: count elements or iterate an object/array with a callback (early stop supported).JSON_GetDepth: maximum nesting depth of a document.JSON_Minify,JSON_Prettify: compact or pretty-print into a caller buffer.*outLengthalways reports the required size, so callers can resize onJSONBadParameter.JSON_StatusToString,JSON_TypeToString: readable names for status and type codes.Build change:
core_json_ext.cis added toJSON_SOURCESinjsonFilePaths.cmake. Linking requires-lm(strtod,isinf).Also adds
examples/demo.c(usage example) andexamples/test_ext.c(ad-hoc test program).Test Steps
gcc -std=c99 -Wall -Wextra -Wpedantic -g -fsanitize=address,undefined -Isource/include source/core_json.c source/core_json_ext.c examples/test_ext.c -o test_ext -lm && ./test_extALL TESTS PASSED.gcc -std=c99 -Wall -Wextra -Isource/include source/core_json.c source/core_json_ext.c examples/demo.c -o demo -lm && ./demoname = Sarthak,age = 20,tags = 3 items,missing -> JSONNotFound, followed by the pretty-printed JSON.Checklist:
Related Issue
None.
By submitting this pull