*
read_file(
const char*filename);
85 static void remove_comments(
char*
string,
const char*start_token,
const char*end_token);
88 static int is_utf16_hex(
const unsigned char*
string);
91 static int is_valid_utf8(
const char*
string,
size_tstring_len);
92 static int is_decimal(
const char*
string,
size_tlength);
112 static int parse_utf_16(
const char**unprocessed,
char**processed);
134output_string[
n] =
'\0';
135strncpy(output_string,
string,
n);
136 returnoutput_string;
148 if(c == 0xC0 || c == 0xC1 || c > 0xF4 ||
IS_CONT(c)) {
150}
else if((c & 0x80) == 0) {
152}
else if((c & 0xE0) == 0xC0) {
154}
else if((c & 0xF0) == 0xE0) {
156}
else if((c & 0xF8) == 0xF0) {
168}
else if(*
len== 2 &&
IS_CONT(
string[1])) {
169cp =
string[0] & 0x1F;
170cp = (cp << 6) | (
string[1] & 0x3F);
172cp = ((
unsignedchar)
string[0]) & 0xF;
173cp = (cp << 6) | (
string[1] & 0x3F);
174cp = (cp << 6) | (
string[2] & 0x3F);
176cp =
string[0] & 0x7;
177cp = (cp << 6) | (
string[1] & 0x3F);
178cp = (cp << 6) | (
string[2] & 0x3F);
179cp = (cp << 6) | (
string[3] & 0x3F);
185 if((cp < 0x80 && *len > 1) ||
186(cp < 0x800 && *len > 2) ||
187(cp < 0x10000 && *len > 3)) {
197 if(cp >= 0xD800 && cp <= 0xDFFF) {
206 const char*string_end =
string+ string_len;
207 while(
string< string_end) {
216 static int is_decimal(
const char*
string,
size_tlength) {
217 if(length > 1 &&
string[0] ==
'0'&&
string[1] !=
'.')
219 if(length > 2 && !
strncmp(
string,
"-0", 2) &&
string[2] !=
'.')
222 if(strchr(
"xX",
string[length]))
228FILE *
fp= fopen(filename,
"r");
242file_contents = (
char*)
parson_malloc(
sizeof(
char) * (file_size + 1));
243 if(!file_contents) {
247 if(fread(file_contents, file_size, 1,
fp) < 1) {
255file_contents[file_size] =
'\0';
256 returnfile_contents;
259 static void remove_comments(
char*
string,
const char*start_token,
const char*end_token) {
260 intin_string = 0, escaped = 0;
262 char*ptr =
NULL, current_char;
263 size_tstart_token_len = strlen(start_token);
264 size_tend_token_len = strlen(end_token);
265 if(start_token_len == 0 || end_token_len == 0)
267 while((current_char = *
string) !=
'\0') {
268 if(current_char ==
'\\'&& !escaped) {
272}
else if(current_char ==
'\"'&& !escaped) {
273in_string = !in_string;
274}
else if(!in_string &&
strncmp(
string, start_token, start_token_len) == 0) {
275 for(
i= 0;
i< start_token_len;
i++)
277 string=
string+ start_token_len;
278ptr = strstr(
string, end_token);
281 for(
i= 0;
i< (ptr -
string) + end_token_len;
i++)
283 string= ptr + end_token_len - 1;
317index =
object->count;
321 object->values[index] =
value;
327 char**temp_names =
NULL;
336temp_names = (
char**)
parson_malloc(new_capacity *
sizeof(
char*));
337 if(temp_names ==
NULL)
341 if(temp_values ==
NULL) {
347memcpy(temp_names, object->
names, object->
count*
sizeof(
char*));
352 object->names = temp_names;
353 object->values = temp_values;
354 object->capacity = new_capacity;
359 size_t i, name_length;
361name_length = strlen(object->
names[
i]);
362 if(name_length !=
n)
365 return object->values[
i];
371 while(object->
count--) {
387new_array->
count= 0;
406 if(new_capacity == 0) {
410 if(new_items ==
NULL) {
417 array->items = new_items;
418 array->capacity = new_capacity;
423 while(
array->count--)
442 while(**
string!=
'\"') {
443 if(**
string==
'\0')
445 if(**
string==
'\\') {
447 if(**
string==
'\0')
455 static int parse_utf_16(
const char**unprocessed,
char**processed) {
456 unsigned intcp, lead, trail;
457 char*processed_ptr = *processed;
458 const char*unprocessed_ptr = *unprocessed;
460 if(!
is_utf16_hex((
const unsigned char*)unprocessed_ptr) || sscanf(unprocessed_ptr,
"%4x", &cp) == EOF)
464}
else if(cp < 0x800) {
465*processed_ptr++ = ((cp >> 6) & 0x1F) | 0xC0;
466*processed_ptr = ((cp ) & 0x3F) | 0x80;
467}
else if(cp < 0xD800 || cp > 0xDFFF) {
468*processed_ptr++ = ((cp >> 12) & 0x0F) | 0xE0;
469*processed_ptr++ = ((cp >> 6) & 0x3F) | 0x80;
470*processed_ptr = ((cp ) & 0x3F) | 0x80;
471}
else if(cp >= 0xD800 && cp <= 0xDBFF) {
473unprocessed_ptr += 4;
474 if(*unprocessed_ptr++ !=
'\\'|| *unprocessed_ptr++ !=
'u'||
475!
is_utf16_hex((
const unsigned char*)unprocessed_ptr) ||
476sscanf(unprocessed_ptr,
"%4x", &trail) == EOF ||
477trail < 0xDC00 || trail > 0xDFFF) {
480cp = ((((lead-0xD800)&0x3FF)<<10)|((trail-0xDC00)&0x3FF))+0x010000;
481*processed_ptr++ = (((cp >> 18) & 0x07) | 0xF0);
482*processed_ptr++ = (((cp >> 12) & 0x3F) | 0x80);
483*processed_ptr++ = (((cp >> 6) & 0x3F) | 0x80);
484*processed_ptr = (((cp ) & 0x3F) | 0x80);
488unprocessed_ptr += 3;
489*processed = processed_ptr;
490*unprocessed = unprocessed_ptr;
498 const char*input_ptr =
input;
499 size_tinitial_size = (
len+ 1) *
sizeof(
char);
500 size_tfinal_size = 0;
502 char*output_ptr =
output;
503 char*resized_output =
NULL;
504 while((*input_ptr !=
'\0') && (size_t)(input_ptr -
input) <
len) {
505 if(*input_ptr ==
'\\') {
507 switch(*input_ptr) {
508 case '\"': *output_ptr =
'\"';
break;
509 case '\\': *output_ptr =
'\\';
break;
510 case '/': *output_ptr =
'/';
break;
511 case 'b': *output_ptr =
'\b';
break;
512 case 'f': *output_ptr =
'\f';
break;
513 case 'n': *output_ptr =
'\n';
break;
514 case 'r': *output_ptr =
'\r';
break;
515 case 't': *output_ptr =
'\t';
break;
523}
else if((
unsigned char)*input_ptr < 0x20) {
526*output_ptr = *input_ptr;
533final_size = (size_t)(output_ptr-
output) + 1;
535 if(resized_output ==
NULL)
537memcpy(resized_output,
output, final_size);
539 returnresized_output;
548 const char*string_start = *
string;
549 size_tstring_len = 0;
551string_len = *
string- string_start - 2;
559 switch(**
string) {
566 case 'f':
case 't':
569 case '0':
case '1':
case '2':
case '3':
case '4':
570 case '5':
case '6':
case '7':
case '8':
case '9':
582 char*new_key =
NULL;
583 if(output_value ==
NULL)
587 if(**
string==
'}') {
591 while(**
string!=
'\0') {
594 if(new_key ==
NULL|| **
string!=
':') {
600 if(new_value ==
NULL) {
613 if(**
string!=
',')
619 if(**
string!=
'}'||
635 if(**
string==
']') {
639 while(**
string!=
'\0') {
641 if(!new_array_value) {
651 if(**
string!=
',')
657 if(**
string!=
']'||
669 if(new_string ==
NULL)
682 if(
strncmp(
"true", *
string, true_token_size) == 0) {
683*
string+= true_token_size;
685}
else if(
strncmp(
"false", *
string, false_token_size) == 0) {
686*
string+= false_token_size;
694 double number= strtod(*
string, &end);
696 if(
is_decimal(*
string, end - *
string)) {
700output_value =
NULL;
707 if(
strncmp(
"null", *
string, token_size) == 0) {
708*
string+= token_size;
715 #define APPEND_STRING(str) do { written = append_string(buf, (str));\ 716 if (written < 0) { return -1; }\ 717 if (buf != NULL) { buf += written; }\ 718 written_total += written; } while(0) 720 #define APPEND_INDENT(level) do { written = append_indent(buf, (level));\ 721 if (written < 0) { return -1; }\ 722 if (buf != NULL) { buf += written; }\ 723 written_total += written; } while(0) 733 intwritten = -1, written_total = 0;
740 if(
count> 0 && is_pretty)
751written_total += written;
757 if(
count> 0 && is_pretty)
760 returnwritten_total;
765 if(
count> 0 && is_pretty)
776written_total += written;
786written_total += written;
792 if(
count> 0 && is_pretty)
795 returnwritten_total;
803written_total += written;
804 returnwritten_total;
810 returnwritten_total;
815 if(num == ((
double)(
int)num))
816written = sprintf(num_buf,
"%d", (
int)num);
823written_total += written;
824 returnwritten_total;
827 returnwritten_total;
836 size_t i= 0,
len= strlen(
string);
838 intwritten = -1, written_total = 0;
840 for(
i= 0;
i<
len;
i++) {
861 returnwritten_total;
866 intwritten = -1, written_total = 0;
867 for(
i= 0;
i< level;
i++) {
870 returnwritten_total;
875 return(
int)strlen(
string);
877 returnsprintf(
buf,
"%s",
string);
885 char*file_contents =
read_file(filename);
887 if(file_contents ==
NULL)
895 char*file_contents =
read_file(filename);
897 if(file_contents ==
NULL)
905 if(
string==
NULL)
912 char*string_mutable_copy =
NULL, *string_mutable_copy_ptr =
NULL;
914 if(string_mutable_copy ==
NULL)
918string_mutable_copy_ptr = string_mutable_copy;
927 if(
object==
NULL|| name ==
NULL)
953 const char*dot_position = strchr(name,
'.');
981 return object?
object->count : 0;
987 return object->names[index];
993 return object->values[index];
1018 return array->items[index];
1116 size_tstring_len = 0;
1117 if(
string==
NULL)
1119string_len = strlen(
string);
1160 const char*temp_string =
NULL, *temp_key =
NULL;
1161 char*temp_string_copy =
NULL;
1175 if(temp_value_copy ==
NULL) {
1196 if(temp_value_copy ==
NULL) {
1214 if(temp_string_copy ==
NULL)
1232 returnres < 0 ? 0 : (size_t)(res + 1);
1238 if(needed_size_in_bytes == 0 || buf_size_in_bytes < needed_size_in_bytes) {
1251 if(serialized_string ==
NULL) {
1254 fp= fopen (filename,
"w");
1259 if(fputs(serialized_string,
fp) == EOF) {
1262 if(fclose(
fp) == EOF) {
1273 if(buf_size_bytes == 0) {
1290 returnres < 0 ? 0 : (size_t)(res + 1);
1296 if(needed_size_in_bytes == 0 || buf_size_in_bytes < needed_size_in_bytes)
1308 if(serialized_string ==
NULL) {
1311 fp= fopen (filename,
"w");
1316 if(fputs(serialized_string,
fp) == EOF) {
1319 if(fclose(
fp) == EOF) {
1330 if(buf_size_bytes == 0) {
1350 size_tlast_element_ix = 0;
1356 if(ix != last_element_ix) {
1358 if(temp_value ==
NULL) {
1361 array->items[ix] = temp_value;
1487 if(old_value !=
NULL) {
1491 object->values[
i] =
value;
1517 const char*dot_pos =
NULL;
1518 char*current_name =
NULL;
1523dot_pos = strchr(name,
'.');
1524 if(dot_pos ==
NULL) {
1529 if(temp_obj ==
NULL) {
1531 if(new_value ==
NULL) {
1592 size_t i= 0, last_item_index = 0;
1600 if(
i!= last_item_index) {
1601 object->names[
i] =
object->names[last_item_index];
1602 object->values[
i] =
object->values[last_item_index];
1604 object->count -= 1;
1612 const char*dot_pos = strchr(name,
'.');
1613 char*current_name =
NULL;
1615 if(dot_pos ==
NULL) {
1620 if(temp_obj ==
NULL) {
1631 if(
object==
NULL) {
1655 switch(schema_type) {
1683 if(temp_value ==
NULL)
1699 const char*a_string =
NULL, *b_string =
NULL;
1701 size_ta_count = 0, b_count = 0,
i= 0;
1705 if(a_type != b_type) {
1714 if(a_count != b_count) {
1717 for(
i= 0;
i< a_count;
i++) {
1729 if(a_count != b_count) {
1732 for(
i= 0;
i< a_count;
i++) {
1743 return strcmp(a_string, b_string) == 0;
static SQLCHAR output[256]
static const char * schema
static char * return_value
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
int strncmp(const char *str1, const char *str2, size_t count)
int strcmp(const char *str1, const char *str2)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
x_JSON_Array * x_json_array(const x_JSON_Value *value)
static x_JSON_Value * x_json_value_init_string_no_copy(char *string)
static void x_json_array_free(x_JSON_Array *array)
static char * process_string(const char *input, size_t len)
x_JSON_Status x_json_array_replace_value(x_JSON_Array *array, size_t ix, x_JSON_Value *value)
x_JSON_Value * x_json_value_init_boolean(int boolean)
static x_JSON_Status x_json_object_add(x_JSON_Object *object, const char *name, x_JSON_Value *value)
static x_JSON_Value * parse_object_value(const char **string, size_t nesting)
double x_json_object_get_number(const x_JSON_Object *object, const char *name)
x_JSON_Status x_json_object_set_value(x_JSON_Object *object, const char *name, x_JSON_Value *value)
x_JSON_Array * x_json_array_get_array(const x_JSON_Array *array, size_t index)
static int verify_utf8_sequence(const unsigned char *string, int *len)
static x_JSON_Value * x_json_object_nget_value(const x_JSON_Object *object, const char *name, size_t n)
x_JSON_Object * x_json_object_dotget_object(const x_JSON_Object *object, const char *name)
x_JSON_Status x_json_object_dotset_value(x_JSON_Object *object, const char *name, x_JSON_Value *value)
const char * x_json_string(const x_JSON_Value *value)
static int append_indent(char *buf, int level)
const char * x_json_object_get_string(const x_JSON_Object *object, const char *name)
void x_json_free_serialized_string(char *string)
int x_json_object_get_boolean(const x_JSON_Object *object, const char *name)
x_JSON_Value * x_json_array_get_value(const x_JSON_Array *array, size_t index)
static x_JSON_Value * parse_number_value(const char **string)
x_JSON_Object * x_json_value_get_object(const x_JSON_Value *value)
x_JSON_Value * x_json_object_get_value_at(const x_JSON_Object *object, size_t index)
x_JSON_Status x_json_array_remove(x_JSON_Array *array, size_t ix)
static char * parson_strdup(const char *string)
#define SKIP_WHITESPACES(str)
x_JSON_Value * x_json_parse_file_with_comments(const char *filename)
static x_JSON_Malloc_Function parson_malloc
x_JSON_Array * x_json_value_get_array(const x_JSON_Value *value)
void x_json_value_free(x_JSON_Value *value)
double x_json_value_get_number(const x_JSON_Value *value)
int x_json_object_has_value(const x_JSON_Object *object, const char *name)
x_JSON_Array * x_json_object_dotget_array(const x_JSON_Object *object, const char *name)
x_JSON_Status x_json_serialize_to_file_pretty(const x_JSON_Value *value, const char *filename)
static char * read_file(const char *filename)
int x_json_value_get_boolean(const x_JSON_Value *value)
static x_JSON_Status x_json_array_add(x_JSON_Array *array, x_JSON_Value *value)
const char * x_json_object_get_name(const x_JSON_Object *object, size_t index)
char * x_json_serialize_to_string(const x_JSON_Value *value)
const char * x_json_value_get_string(const x_JSON_Value *value)
x_JSON_Status x_json_object_set_number(x_JSON_Object *object, const char *name, double number)
x_JSON_Value * x_json_value_init_object(void)
x_JSON_Value * x_json_value_deep_copy(const x_JSON_Value *value)
#define DOUBLE_SERIALIZATION_FORMAT
size_t x_json_serialization_size_pretty(const x_JSON_Value *value)
static char * get_quoted_string(const char **string)
static void skip_quotes(const char **string)
double x_json_number(const x_JSON_Value *value)
#define ARRAY_MAX_CAPACITY
x_JSON_Status x_json_serialize_to_buffer_pretty(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes)
static int is_decimal(const char *string, size_t length)
x_JSON_Status x_json_array_clear(x_JSON_Array *array)
static x_JSON_Value * parse_boolean_value(const char **string)
x_JSON_Status x_json_array_replace_boolean(x_JSON_Array *array, size_t i, int boolean)
static int x_json_serialize_to_buffer_r(const x_JSON_Value *value, char *buf, int level, int is_pretty, char *num_buf)
#define STARTING_CAPACITY
x_JSON_Status x_json_validate(const x_JSON_Value *schema, const x_JSON_Value *value)
void x_json_set_allocation_functions(x_JSON_Malloc_Function malloc_fun, x_JSON_Free_Function free_fun)
int x_json_boolean(const x_JSON_Value *value)
char * x_json_serialize_to_string_pretty(const x_JSON_Value *value)
x_JSON_Object * x_json_object(const x_JSON_Value *value)
x_JSON_Status x_json_array_append_value(x_JSON_Array *array, x_JSON_Value *value)
static x_JSON_Status x_json_object_resize(x_JSON_Object *object, size_t new_capacity)
x_JSON_Value * x_json_object_dotget_value(const x_JSON_Object *object, const char *name)
double x_json_object_dotget_number(const x_JSON_Object *object, const char *name)
#define APPEND_INDENT(level)
static int is_valid_utf8(const char *string, size_t string_len)
static x_JSON_Value * parse_value(const char **string, size_t nesting)
x_JSON_Status x_json_array_append_null(x_JSON_Array *array)
x_JSON_Status x_json_object_dotset_number(x_JSON_Object *object, const char *name, double number)
#define OBJECT_MAX_CAPACITY
x_JSON_Object * x_json_array_get_object(const x_JSON_Array *array, size_t index)
x_JSON_Value * x_json_value_init_string(const char *string)
const char * x_json_array_get_string(const x_JSON_Array *array, size_t index)
x_JSON_Status x_json_array_replace_number(x_JSON_Array *array, size_t i, double number)
x_JSON_Value * x_json_parse_string_with_comments(const char *string)
static void x_json_object_free(x_JSON_Object *object)
static x_JSON_Object * x_json_object_init(void)
x_JSON_Status x_json_value_equals(const x_JSON_Value *a, const x_JSON_Value *b)
x_JSON_Status x_json_object_dotset_string(x_JSON_Object *object, const char *name, const char *string)
x_JSON_Value * x_json_parse_string(const char *string)
x_JSON_Value * x_json_value_init_array(void)
int x_json_object_dotget_boolean(const x_JSON_Object *object, const char *name)
x_JSON_Status x_json_object_set_string(x_JSON_Object *object, const char *name, const char *string)
x_JSON_Value * x_json_value_init_null(void)
static int append_string(char *buf, const char *string)
static x_JSON_Value * parse_array_value(const char **string, size_t nesting)
x_JSON_Array * x_json_object_get_array(const x_JSON_Object *object, const char *name)
x_JSON_Status x_json_array_replace_null(x_JSON_Array *array, size_t i)
static int x_json_serialize_string(const char *string, char *buf)
static x_JSON_Value * parse_string_value(const char **string)
size_t x_json_array_get_count(const x_JSON_Array *array)
x_JSON_Status x_json_object_dotset_boolean(x_JSON_Object *object, const char *name, int boolean)
x_JSON_Status x_json_object_set_boolean(x_JSON_Object *object, const char *name, int boolean)
#define APPEND_STRING(str)
x_JSON_Status x_json_object_clear(x_JSON_Object *object)
int x_json_object_dothas_value(const x_JSON_Object *object, const char *name)
static x_JSON_Status x_json_array_resize(x_JSON_Array *array, size_t new_capacity)
size_t x_json_serialization_size(const x_JSON_Value *value)
static char * parson_strndup(const char *string, size_t n)
x_JSON_Status x_json_array_append_number(x_JSON_Array *array, double number)
x_JSON_Status x_json_serialize_to_file(const x_JSON_Value *value, const char *filename)
static x_JSON_Array * x_json_array_init(void)
x_JSON_Value_Type x_json_value_get_type(const x_JSON_Value *value)
static int is_utf16_hex(const unsigned char *string)
x_JSON_Status x_json_array_append_boolean(x_JSON_Array *array, int boolean)
int x_json_object_dothas_value_of_type(const x_JSON_Object *object, const char *name, x_JSON_Value_Type type)
x_JSON_Value_Type x_json_type(const x_JSON_Value *value)
x_JSON_Status x_json_array_append_string(x_JSON_Array *array, const char *string)
static int parse_utf_16(const char **unprocessed, char **processed)
x_JSON_Status x_json_array_replace_string(x_JSON_Array *array, size_t i, const char *string)
size_t x_json_object_get_count(const x_JSON_Object *object)
double x_json_array_get_number(const x_JSON_Array *array, size_t index)
x_JSON_Value * x_json_parse_file(const char *filename)
x_JSON_Status x_json_object_set_null(x_JSON_Object *object, const char *name)
int x_json_object_has_value_of_type(const x_JSON_Object *object, const char *name, x_JSON_Value_Type type)
x_JSON_Status x_json_object_dotset_null(x_JSON_Object *object, const char *name)
x_JSON_Status x_json_object_remove(x_JSON_Object *object, const char *name)
x_JSON_Value * x_json_object_get_value(const x_JSON_Object *object, const char *name)
static int num_bytes_in_utf8_sequence(unsigned char c)
x_JSON_Status x_json_serialize_to_buffer(const x_JSON_Value *value, char *buf, size_t buf_size_in_bytes)
const char * x_json_object_dotget_string(const x_JSON_Object *object, const char *name)
union x_json_value_value x_JSON_Value_Value
int x_json_array_get_boolean(const x_JSON_Array *array, size_t index)
x_JSON_Object * x_json_object_get_object(const x_JSON_Object *object, const char *name)
static void remove_comments(char *string, const char *start_token, const char *end_token)
x_JSON_Status x_json_object_dotremove(x_JSON_Object *object, const char *name)
static x_JSON_Free_Function parson_free
x_JSON_Value * x_json_value_init_number(double number)
static x_JSON_Value * parse_null_value(const char **string)
void *(* x_JSON_Malloc_Function)(size_t)
void(* x_JSON_Free_Function)(void *)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4