mirror of
https://github.com/kgabis/parson.git
synced 2025-05-10 03:32:08 +00:00
Additional code cleanup.
Removed redundant typedefs, renamed JSON_value_t to JSON_Value_Type and JSON_value_value to JSON_Value_Value to make names more consistent across project. Added project's name and url above license.
This commit is contained in:
parent
ede8ea497a
commit
202f16cc5c
21
parson.c
21
parson.c
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 Krzysztof Gabis
|
Copyright (c) 2012 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
|
||||||
@ -44,25 +45,25 @@ typedef union json_value_value {
|
|||||||
JSON_Array *array;
|
JSON_Array *array;
|
||||||
int boolean;
|
int boolean;
|
||||||
int null;
|
int null;
|
||||||
} json_value_value;
|
} JSON_Value_Value;
|
||||||
|
|
||||||
typedef struct json_value_t {
|
struct json_value_t {
|
||||||
JSON_value_t type;
|
JSON_Value_Type type;
|
||||||
json_value_value value;
|
JSON_Value_Value value;
|
||||||
} json_value_t;
|
};
|
||||||
|
|
||||||
typedef struct json_object_t {
|
struct json_object_t {
|
||||||
const char **names;
|
const char **names;
|
||||||
JSON_Value **values;
|
JSON_Value **values;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} json_object_t;
|
};
|
||||||
|
|
||||||
typedef struct json_array_t {
|
struct json_array_t {
|
||||||
JSON_Value **items;
|
JSON_Value **items;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} json_array_t;
|
};
|
||||||
|
|
||||||
/* JSON Object */
|
/* JSON Object */
|
||||||
static JSON_Object * json_object_init(void);
|
static JSON_Object * json_object_init(void);
|
||||||
@ -642,7 +643,7 @@ size_t json_array_get_count(const JSON_Array *array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* JSON Value API */
|
/* JSON Value API */
|
||||||
JSON_value_t json_value_get_type(const JSON_Value *value) {
|
JSON_Value_Type json_value_get_type(const JSON_Value *value) {
|
||||||
return value ? value->type : JSONError;
|
return value ? value->type : JSONError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
parson.h
18
parson.h
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 Krzysztof Gabis
|
Copyright (c) 2012 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
|
||||||
@ -19,6 +20,7 @@
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef parson_parson_h
|
#ifndef parson_parson_h
|
||||||
#define parson_parson_h
|
#define parson_parson_h
|
||||||
|
|
||||||
@ -27,16 +29,14 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
/* Types and enums */
|
||||||
/* Data structures, enums and typedefs */
|
|
||||||
typedef struct json_object_t JSON_Object;
|
typedef struct json_object_t JSON_Object;
|
||||||
typedef struct json_array_t JSON_Array;
|
typedef struct json_array_t JSON_Array;
|
||||||
typedef struct json_value_t JSON_Value;
|
typedef struct json_value_t JSON_Value;
|
||||||
|
|
||||||
typedef enum JSON_value_t {
|
typedef enum json_value_type {
|
||||||
JSONError = 0,
|
JSONError = 0,
|
||||||
JSONNull = 1,
|
JSONNull = 1,
|
||||||
JSONString = 2,
|
JSONString = 2,
|
||||||
@ -44,7 +44,7 @@ typedef enum JSON_value_t {
|
|||||||
JSONObject = 4,
|
JSONObject = 4,
|
||||||
JSONArray = 5,
|
JSONArray = 5,
|
||||||
JSONBoolean = 6
|
JSONBoolean = 6
|
||||||
} JSON_value_t;
|
} JSON_Value_Type;
|
||||||
|
|
||||||
/* Parses first JSON value in a file, returns NULL in case of error */
|
/* Parses first JSON value in a file, returns NULL in case of error */
|
||||||
JSON_Value * json_parse_file(const char *filename);
|
JSON_Value * json_parse_file(const char *filename);
|
||||||
@ -55,9 +55,9 @@ JSON_Value * json_parse_string(const char *string);
|
|||||||
/* JSON Object */
|
/* JSON Object */
|
||||||
JSON_Value * json_object_get_value (const JSON_Object *object, const char *name);
|
JSON_Value * json_object_get_value (const JSON_Object *object, const char *name);
|
||||||
const char * json_object_get_string (const JSON_Object *object, const char *name);
|
const char * json_object_get_string (const JSON_Object *object, const char *name);
|
||||||
double json_object_get_number (const JSON_Object *object, const char *name);
|
|
||||||
JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
|
JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
|
||||||
JSON_Array * json_object_get_array (const JSON_Object *object, const char *name);
|
JSON_Array * json_object_get_array (const JSON_Object *object, const char *name);
|
||||||
|
double json_object_get_number (const JSON_Object *object, const char *name);
|
||||||
int json_object_get_boolean(const JSON_Object *object, const char *name);
|
int json_object_get_boolean(const JSON_Object *object, const char *name);
|
||||||
|
|
||||||
/* dotget functions enable addressing values with dot notation in nested objects,
|
/* dotget functions enable addressing values with dot notation in nested objects,
|
||||||
@ -66,22 +66,22 @@ int json_object_get_boolean(const JSON_Object *object, const char *nam
|
|||||||
this way. */
|
this way. */
|
||||||
JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *name);
|
JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *name);
|
||||||
const char * json_object_dotget_string (const JSON_Object *object, const char *name);
|
const char * json_object_dotget_string (const JSON_Object *object, const char *name);
|
||||||
double json_object_dotget_number (const JSON_Object *object, const char *name);
|
|
||||||
JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
|
JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
|
||||||
JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name);
|
JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name);
|
||||||
|
double json_object_dotget_number (const JSON_Object *object, const char *name);
|
||||||
int json_object_dotget_boolean(const JSON_Object *object, const char *name);
|
int json_object_dotget_boolean(const JSON_Object *object, const char *name);
|
||||||
|
|
||||||
/* JSON Array */
|
/* JSON Array */
|
||||||
JSON_Value * json_array_get_value (const JSON_Array *array, size_t index);
|
JSON_Value * json_array_get_value (const JSON_Array *array, size_t index);
|
||||||
const char * json_array_get_string (const JSON_Array *array, size_t index);
|
const char * json_array_get_string (const JSON_Array *array, size_t index);
|
||||||
double json_array_get_number (const JSON_Array *array, size_t index);
|
|
||||||
JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
|
JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
|
||||||
JSON_Array * json_array_get_array (const JSON_Array *array, size_t index);
|
JSON_Array * json_array_get_array (const JSON_Array *array, size_t index);
|
||||||
|
double json_array_get_number (const JSON_Array *array, size_t index);
|
||||||
int json_array_get_boolean(const JSON_Array *array, size_t index);
|
int json_array_get_boolean(const JSON_Array *array, size_t index);
|
||||||
size_t json_array_get_count (const JSON_Array *array);
|
size_t json_array_get_count (const JSON_Array *array);
|
||||||
|
|
||||||
/* JSON Value */
|
/* JSON Value */
|
||||||
JSON_value_t json_value_get_type (const JSON_Value *value);
|
JSON_Value_Type json_value_get_type (const JSON_Value *value);
|
||||||
JSON_Object * json_value_get_object (const JSON_Value *value);
|
JSON_Object * json_value_get_object (const JSON_Value *value);
|
||||||
JSON_Array * json_value_get_array (const JSON_Value *value);
|
JSON_Array * json_value_get_array (const JSON_Value *value);
|
||||||
const char * json_value_get_string (const JSON_Value *value);
|
const char * json_value_get_string (const JSON_Value *value);
|
||||||
|
2
tests.c
2
tests.c
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
Parson ( http://kgabis.github.com/parson/ )
|
||||||
Copyright (c) 2012 Krzysztof Gabis
|
Copyright (c) 2012 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
|
||||||
@ -120,7 +121,6 @@ void test_suite_2(void) {
|
|||||||
tests_failed++;
|
tests_failed++;
|
||||||
}
|
}
|
||||||
TEST(json_object_dotget_boolean(object, "nested true"));
|
TEST(json_object_dotget_boolean(object, "nested true"));
|
||||||
|
|
||||||
json_value_free(root_value);
|
json_value_free(root_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user