mirror of
https://github.com/kgabis/parson.git
synced 2026-01-30 13:48:09 -05:00
Fixes a bug in json_array_remove and adds relevant tests (thanks to KB for finding this).
Also - it's 2016, time to update copyright notices, yay!
This commit is contained in:
parent
8324ff92bf
commit
c9b920c4a3
13
parson.c
13
parson.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Parson ( http://kgabis.github.com/parson/ )
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 - 2015 Krzysztof Gabis
|
Copyright (c) 2012 - 2016 Krzysztof Gabis
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -1322,21 +1322,26 @@ char * json_serialize_to_string_pretty(const JSON_Value *value) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void json_free_serialized_string(char *string) {
|
void json_free_serialized_string(char *string) {
|
||||||
parson_free(string);
|
parson_free(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_Status json_array_remove(JSON_Array *array, size_t ix) {
|
JSON_Status json_array_remove(JSON_Array *array, size_t ix) {
|
||||||
|
JSON_Value *temp_value = NULL;
|
||||||
size_t last_element_ix = 0;
|
size_t last_element_ix = 0;
|
||||||
if (array == NULL || ix >= json_array_get_count(array)) {
|
if (array == NULL || ix >= json_array_get_count(array)) {
|
||||||
return JSONFailure;
|
return JSONFailure;
|
||||||
}
|
}
|
||||||
last_element_ix = json_array_get_count(array) - 1;
|
last_element_ix = json_array_get_count(array) - 1;
|
||||||
json_value_free(json_array_get_value(array, ix));
|
json_value_free(json_array_get_value(array, ix));
|
||||||
|
if (ix != last_element_ix) { /* Replace value with one from the end of array */
|
||||||
|
temp_value = json_array_get_value(array, last_element_ix);
|
||||||
|
if (temp_value == NULL) {
|
||||||
|
return JSONFailure;
|
||||||
|
}
|
||||||
|
array->items[ix] = temp_value;
|
||||||
|
}
|
||||||
array->count -= 1;
|
array->count -= 1;
|
||||||
if (ix != last_element_ix) /* Replace value with one from the end of array */
|
|
||||||
array->items[ix] = json_array_get_value(array, last_element_ix);
|
|
||||||
return JSONSuccess;
|
return JSONSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
parson.h
2
parson.h
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Parson ( http://kgabis.github.com/parson/ )
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 - 2015 Krzysztof Gabis
|
Copyright (c) 2012 - 2016 Krzysztof Gabis
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
9
tests.c
9
tests.c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Parson ( http://kgabis.github.com/parson/ )
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 - 2015 Krzysztof Gabis
|
Copyright (c) 2012 - 2016 Krzysztof Gabis
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -311,7 +311,14 @@ void test_suite_5(void) {
|
|||||||
|
|
||||||
TEST(json_array_append_string(json_object_get_array(obj, "interests"), NULL) == JSONFailure);
|
TEST(json_array_append_string(json_object_get_array(obj, "interests"), NULL) == JSONFailure);
|
||||||
|
|
||||||
|
TEST(json_array_append_string(interests_arr, "Writing") == JSONSuccess);
|
||||||
|
TEST(json_array_remove(interests_arr, 0) == JSONSuccess);
|
||||||
|
TEST(json_array_remove(interests_arr, 1) == JSONSuccess);
|
||||||
|
TEST(json_array_remove(interests_arr, 0) == JSONSuccess);
|
||||||
|
TEST(json_array_remove(interests_arr, 0) == JSONFailure); /* should be empty by now */
|
||||||
|
|
||||||
|
TEST(json_object_remove(obj, "interests") == JSONSuccess);
|
||||||
|
|
||||||
/* UTF-8 tests */
|
/* UTF-8 tests */
|
||||||
TEST(json_object_set_string(obj, "correct string", "κόσμε") == JSONSuccess);
|
TEST(json_object_set_string(obj, "correct string", "κόσμε") == JSONSuccess);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user