mirror of
https://github.com/json-c/json-c.git
synced 2026-03-31 10:59:06 +08:00
clang-format the files
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "json.h"
|
||||
#include "parse_flags.h"
|
||||
|
||||
static int sort_fn (const void *j1, const void *j2)
|
||||
static int sort_fn(const void *j1, const void *j2)
|
||||
{
|
||||
json_object * const *jso1, * const *jso2;
|
||||
json_object *const *jso1, *const *jso2;
|
||||
int i1, i2;
|
||||
|
||||
jso1 = (json_object* const*)j1;
|
||||
jso2 = (json_object* const*)j2;
|
||||
jso1 = (json_object *const *)j1;
|
||||
jso2 = (json_object *const *)j2;
|
||||
if (!*jso1 && !*jso2)
|
||||
return 0;
|
||||
if (!*jso1)
|
||||
@@ -38,7 +38,8 @@ static const char *to_json_string(json_object *obj, int flags)
|
||||
copy = strdup(result);
|
||||
if (copy == NULL)
|
||||
printf("to_json_string: Allocation failed!\n");
|
||||
else {
|
||||
else
|
||||
{
|
||||
result = json_object_to_json_string_ext(obj, flags);
|
||||
if (length != strlen(result))
|
||||
printf("to_json_string: Length mismatch!\n");
|
||||
@@ -48,7 +49,7 @@ static const char *to_json_string(json_object *obj, int flags)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#define json_object_to_json_string(obj) to_json_string(obj,sflags)
|
||||
#define json_object_to_json_string(obj) to_json_string(obj, sflags)
|
||||
#else
|
||||
/* no special define */
|
||||
#endif
|
||||
@@ -84,7 +85,7 @@ void test_array_del_idx()
|
||||
orig_array_len = json_object_array_length(my_array);
|
||||
|
||||
printf("my_array=\n");
|
||||
for(ii = 0; ii < json_object_array_length(my_array); ii++)
|
||||
for (ii = 0; ii < json_object_array_length(my_array); ii++)
|
||||
{
|
||||
json_object *obj = json_object_array_get_idx(my_array, ii);
|
||||
printf("\t[%d]=%s\n", (int)ii, json_object_to_json_string(obj));
|
||||
@@ -94,38 +95,38 @@ void test_array_del_idx()
|
||||
for (ii = 0; ii < orig_array_len; ii++)
|
||||
{
|
||||
rc = json_object_array_del_idx(my_array, 0, 1);
|
||||
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n",
|
||||
rc, json_object_to_json_string(my_array));
|
||||
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc,
|
||||
json_object_to_json_string(my_array));
|
||||
}
|
||||
|
||||
/* One more time, with the empty array: */
|
||||
rc = json_object_array_del_idx(my_array, 0, 1);
|
||||
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n",
|
||||
rc, json_object_to_json_string(my_array));
|
||||
printf("after del_idx(0,1)=%d, my_array.to_string()=%s\n", rc,
|
||||
json_object_to_json_string(my_array));
|
||||
|
||||
json_object_put(my_array);
|
||||
|
||||
/* Delete all array indexes at once */
|
||||
my_array = make_array();
|
||||
rc = json_object_array_del_idx(my_array, 0, orig_array_len);
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n",
|
||||
(int)orig_array_len, rc, json_object_to_json_string(my_array));
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)orig_array_len, rc,
|
||||
json_object_to_json_string(my_array));
|
||||
|
||||
json_object_put(my_array);
|
||||
|
||||
/* Delete *more* than all array indexes at once */
|
||||
my_array = make_array();
|
||||
rc = json_object_array_del_idx(my_array, 0, orig_array_len + 1);
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n",
|
||||
(int)(orig_array_len + 1), rc, json_object_to_json_string(my_array));
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len + 1), rc,
|
||||
json_object_to_json_string(my_array));
|
||||
|
||||
json_object_put(my_array);
|
||||
|
||||
|
||||
/* Delete some array indexes, then add more */
|
||||
my_array = make_array();
|
||||
rc = json_object_array_del_idx(my_array, 0, orig_array_len - 1);
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n",
|
||||
(int)(orig_array_len - 1), rc, json_object_to_json_string(my_array));
|
||||
printf("after del_idx(0,%d)=%d, my_array.to_string()=%s\n", (int)(orig_array_len - 1), rc,
|
||||
json_object_to_json_string(my_array));
|
||||
json_object_array_add(my_array, json_object_new_string("s1"));
|
||||
json_object_array_add(my_array, json_object_new_string("s2"));
|
||||
json_object_array_add(my_array, json_object_new_string("s3"));
|
||||
@@ -162,13 +163,15 @@ int main(int argc, char **argv)
|
||||
my_string = json_object_new_string("/");
|
||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||
printf("my_string.to_string(NOSLASHESCAPE)=%s\n", json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
printf("my_string.to_string(NOSLASHESCAPE)=%s\n",
|
||||
json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
json_object_put(my_string);
|
||||
|
||||
my_string = json_object_new_string("/foo/bar/baz");
|
||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||
printf("my_string.to_string(NOSLASHESCAPE)=%s\n", json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
printf("my_string.to_string(NOSLASHESCAPE)=%s\n",
|
||||
json_object_to_json_string_ext(my_string, JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
json_object_put(my_string);
|
||||
|
||||
my_string = json_object_new_string("foo");
|
||||
@@ -188,7 +191,7 @@ int main(int argc, char **argv)
|
||||
json_object_array_add(my_array, json_object_new_int(3));
|
||||
json_object_array_put_idx(my_array, 4, json_object_new_int(5));
|
||||
printf("my_array=\n");
|
||||
for(i=0; i < json_object_array_length(my_array); i++)
|
||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||
{
|
||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||
@@ -205,7 +208,7 @@ int main(int argc, char **argv)
|
||||
json_object_array_add(my_array, json_object_new_int(2));
|
||||
json_object_array_put_idx(my_array, 4, json_object_new_int(0));
|
||||
printf("my_array=\n");
|
||||
for(i=0; i < json_object_array_length(my_array); i++)
|
||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||
{
|
||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||
@@ -213,7 +216,7 @@ int main(int argc, char **argv)
|
||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||
json_object_array_sort(my_array, sort_fn);
|
||||
printf("my_array=\n");
|
||||
for(i=0; i < json_object_array_length(my_array); i++)
|
||||
for (i = 0; i < json_object_array_length(my_array); i++)
|
||||
{
|
||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||
printf("\t[%d]=%s\n", (int)i, json_object_to_json_string(obj));
|
||||
|
||||
Reference in New Issue
Block a user