ibireme / yyjson

The fastest JSON library in C
https://ibireme.github.io/yyjson/doc/doxygen/html/
MIT License
3.04k stars 262 forks source link

Add functions to get type-specific values specified by JSON Pointer #116

Closed chad-earthscope closed 1 year ago

chad-earthscope commented 1 year ago

This PR adds the following convenience functions that get a value from yyjson_doc as specified by a JSON Pointer:

yyjson_get_bool_pointer()
yyjson_get_uint_pointer()
yyjson_get_sint_pointer()
yyjson_get_real_pointer()
yyjson_get_num_pointer()
yyjson_get_str_pointer()

Additionally, these functions allow the caller to disambiguate non-existing or type-mismatches from actual values of false, 0 and 0.0, which is ambiguous using by their non-pointer variants (yyget_get_bool(), yyjson_get_uint(),...).

Tests included.

codecov[bot] commented 1 year ago

Codecov Report

Merging #116 (9ae0b62) into develop (9e9ca66) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #116   +/-   ##
========================================
  Coverage    98.50%   98.50%           
========================================
  Files            2        2           
  Lines         2480     2480           
========================================
  Hits          2443     2443           
  Misses          37       37           
Impacted Files Coverage Δ
src/yyjson.h 87.05% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

ibireme commented 1 year ago

Thanks for the pull request, it looks good.

As the document https://github.com/ibireme/yyjson/blob/master/doc/API.md#null-check says, public APIs check every input argument for NULL, so we can simplify some code, as I mentioned in review comments.