Skip to content
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

Issue #338, add json_object_add_int functions #363

Merged
merged 1 commit into from Nov 27, 2017

Conversation

jvijtiuk
Copy link

This adds json_object_add_int and json_object_add_int64 functions, instead of the increment functions requested in #338 since add functions are more general.

* @param val the value to add
* @returns 1 if the addition succeded, 0 otherwise
*/
JSON_EXPORT int json_object_add_int(struct json_object *obj, int val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe more of a preference [from me] here, but, keeping the name json_object_inc_int() [like mentioned in issue #338 ] or similar, could be a good idea, because it makes it clearer that it's incrementing an int value;

in the context of libjson-c a name that like json_object_add_xxx reminds me of the json_object_object_add() or json_object_array_add() functions where a JSON object is added to a another JSON object

i'd also rename the int val param to int inc
and you can also create a convenience macro called json_object_dec_int() where

#define json_object_dec_int(x,y)    json_object_inc_int(x, -(y))

but these are all just preferences/thoughts :)

@hawicz
Copy link
Member

hawicz commented Nov 27, 2017

Merging as-is first, but I'm going to consolidate the 32/64-bit versions shortly.

@hawicz hawicz merged commit 91662a5 into json-c:master Nov 27, 2017
@hawicz
Copy link
Member

hawicz commented Nov 27, 2017

Also, I like @commodo's suggestion of keeping the "inc" in the name, so I'll rename it.

@hawicz
Copy link
Member

hawicz commented Nov 27, 2017

Actually, to be consistent with other methods that mutate existing objects (e.g. json_object_array_sort) I'm going to use json_object_int_inc() here.

@hawicz
Copy link
Member

hawicz commented Nov 27, 2017

Done in commit 3628f16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants