97 lines
2.0 KiB
C
97 lines
2.0 KiB
C
/**
|
|
rjp
|
|
Copyright (C) 2018 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef RJP_H
|
|
#define RJP_H
|
|
|
|
#include <stddef.h> //size_t
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"{
|
|
#endif
|
|
//type of data
|
|
enum JSON_type{
|
|
json_object,
|
|
json_string,
|
|
json_integer,
|
|
json_dfloat,
|
|
json_boolean,
|
|
json_array,
|
|
json_null
|
|
};
|
|
|
|
enum JSON_flags{
|
|
json_flag_string = 1, //in a string
|
|
json_flag_comment = 2, //in a comment block
|
|
json_flag_search_name = 4, //looking for key/value pair
|
|
json_flag_escape = 16 //escaped character in a string
|
|
};
|
|
|
|
//keep track of string length
|
|
struct JSON_string{
|
|
char* value;
|
|
size_t length;
|
|
};
|
|
|
|
//keep a linked list of all members of a given object
|
|
struct JSON_object{
|
|
struct JSON_object_member* members;
|
|
size_t num_members;
|
|
};
|
|
|
|
//keep array plus length
|
|
struct JSON_array{
|
|
struct JSON_array_element* elements;
|
|
size_t num_elements;
|
|
};
|
|
|
|
//hold any json data type
|
|
struct JSON_value{
|
|
enum JSON_type type;
|
|
union{
|
|
long integer;
|
|
double dfloat;
|
|
char boolean;
|
|
struct JSON_object object;
|
|
struct JSON_string string;
|
|
struct JSON_array array;
|
|
};
|
|
struct JSON_value* parent;
|
|
};
|
|
|
|
struct JSON_array_element{
|
|
struct JSON_value value;
|
|
struct JSON_array_element* next;
|
|
};
|
|
|
|
//A member of an object
|
|
struct JSON_object_member{
|
|
struct JSON_string name;
|
|
struct JSON_value value;
|
|
struct JSON_object_member* next;
|
|
};
|
|
|
|
void free_json(struct JSON_value* root);
|
|
struct JSON_value* parse_json(const char* str);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|