-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json_pointer: extend setter & getter with printf() style arguments #287
Conversation
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
How about switching around the arguments so the printf-style args are adjacent to the format? i.e.
Also, since this can result in some dangerous usage if you're not careful, please recommend always specifying a format, e.g. json_pointer_get(jo1, &jo2, "%s", "/some/path"), in the docs for the cases where you don't want to use the printf feature, and adjust the fixed-string examples/tests to call it that way. |
I personally like the current order of args in I was also thinking about not changing Regarding always specifying a format ; hmm, I think |
Re: order of args: ok, that makes sense. json_pointer_get(jo1, &jo2, "%s", "/some/path") and json_pointer_get(jo1, &jo2, "/some/path") are definitely not the same in terms of danger. I meant "/some/path" to include not just hard coded strings, but any arbitrary path that might be passed in. Having separate printf-format-enabled and plain variants of the get and set functions sounds like a good idea. How about json_pointer_getf and json_pointer_setf, so the names aren't too long? |
@hawicz So, the getf/setf variants have the params switched ( so that path_fmt is last ; was not sure how you'd prefer them ; if you want I can switch them ) |
These include support for printf() style args for path. Adds support for calling with 'json_pointer_getf(obj, &res, "/foo/%d/%s", 0, bar)' style args. Makes it easier for doing more dynamic stuff/magic, without needing to use vasprintf() externally. Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
…mplate Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
…s template Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Adds support for calling with 'json_pointer_get(obj, "/foo/%d/%s", &res, 0, bar)'
style args.
Makes it easier for doing more dynamic stuff/magic, without
needing to use vasprintf() externally.
Other stuff is cleanup, and extend the current json_pointer test.
Signed-off-by: Alexandru Ardelean ardeleanalex@gmail.com