Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50c7a055ec | ||
|
|
6771d00c6e | ||
|
|
71661cd9ad | ||
|
|
46b7b56852 | ||
|
|
fd7d9988b8 |
@@ -4,8 +4,8 @@ include(GNUInstallDirs)
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
project(rjp)
|
||||
set(rjp_VERSION_MAJOR 0)
|
||||
set(rjp_VERSION_MINOR 5)
|
||||
set(rjp_VERSION_REVISION 0)
|
||||
set(rjp_VERSION_MINOR 6)
|
||||
set(rjp_VERSION_REVISION 2)
|
||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||
configure_file(
|
||||
"${INCLUDE_PATH}/config.h.in"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
@@ -137,10 +137,10 @@ size_t rjp_member_name_length(RJP_value* member);
|
||||
RJP_search_res rjp_search_member(const RJP_value* object, const char* search, size_t skip);
|
||||
//Search for first occurance of multiple keys. Returns first occurance of each.
|
||||
//Assumes dest is large enough to hold maximum num items.
|
||||
size_t rjp_search_members(const RJP_value* object, size_t num, const char** searches, RJP_search_res* dest, size_t skip);
|
||||
size_t rjp_search_members(const RJP_value* object, size_t num, const char* const* searches, RJP_search_res* dest, size_t skip);
|
||||
//Search for multiple occurances of multiple keys. Returns pointer to list of matches.
|
||||
//Returned pointer must be freed using rjp_free
|
||||
RJP_search_res* rjp_search_members_multi(const RJP_value* object, size_t num, const char** searches, size_t* rsize, size_t skip);
|
||||
RJP_search_res* rjp_search_members_multi(const RJP_value* object, size_t num, const char* const* searches, size_t* rsize, size_t skip);
|
||||
//Access first element of a json array
|
||||
RJP_value* rjp_get_element(const RJP_value* array);
|
||||
//Access next element of a json array given the previous element
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <stddef.h> //size_t
|
||||
|
||||
int _rjp__is_whitespace(char c);
|
||||
char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, int* column);
|
||||
char* _rjp__parse_string(RJP_value* root, const char* str, int* inclen, int* len, int* row, int* column);
|
||||
size_t _rjp__array_strlen(RJP_value* arr);
|
||||
size_t _rjp__object_strlen(RJP_value* root);
|
||||
size_t _rjp__value_strlen(RJP_value* root);
|
||||
|
||||
13
src/input.c
13
src/input.c
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
@@ -104,14 +104,15 @@ RJP_value* rjp_parse(const char* str){
|
||||
syntax_error("Key found outside of object definition!", row, column);
|
||||
|
||||
int keylen;
|
||||
char* new_string = _rjp__parse_string(root, ++str, &keylen, &row, &column);
|
||||
int inclen;
|
||||
char* new_string = _rjp__parse_string(root, ++str, &inclen, &keylen, &row, &column);
|
||||
if(!new_string){
|
||||
if(!keylen)
|
||||
syntax_error("Cannot have empty key name!", row, column);
|
||||
return NULL;
|
||||
}
|
||||
_rjp__add_member_no_alloc(&curr->object, new_string, keylen);
|
||||
str += keylen;
|
||||
str += inclen;
|
||||
*top = json_colon;
|
||||
//end of this object (object is empty)
|
||||
}else if(c == '}'){
|
||||
@@ -183,9 +184,9 @@ RJP_value* rjp_parse(const char* str){
|
||||
}
|
||||
//strings
|
||||
else if(c == '"'){
|
||||
int vallen;
|
||||
int vallen, inclen;
|
||||
++str;
|
||||
char* new_string = _rjp__parse_string(root, str, &vallen, &row, &column);
|
||||
char* new_string = _rjp__parse_string(root, str, &inclen, &vallen, &row, &column);
|
||||
if(!new_string){
|
||||
if(vallen == 0){
|
||||
new_string = rjp_calloc(1, 1);
|
||||
@@ -194,7 +195,7 @@ RJP_value* rjp_parse(const char* str){
|
||||
}
|
||||
}
|
||||
_rjp__add_value(curr, rjp_string(new_string, vallen));
|
||||
str += vallen;
|
||||
str += inclen;
|
||||
*top = json_comma;
|
||||
}
|
||||
//numbers
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
|
||||
16
src/rjp.c
16
src/rjp.c
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
@@ -138,10 +138,11 @@ RJP_search_res rjp_search_member(const RJP_value* object, const char* search, si
|
||||
return (RJP_search_res){0};
|
||||
}
|
||||
|
||||
size_t rjp_search_members(const RJP_value* object, size_t num, const char** searches, RJP_search_res* dest, size_t skip){
|
||||
size_t rjp_search_members(const RJP_value* object, size_t num, const char* const* searches, RJP_search_res* dest, size_t skip){
|
||||
const char** tmp = rjp_alloc(num*sizeof(char*));
|
||||
for(size_t i = 0;i < num;++i){
|
||||
tmp[i] = searches[i];
|
||||
dest[i] = (RJP_search_res){0};
|
||||
}
|
||||
RJP_value* member = rjp_get_member(object);
|
||||
size_t objindex = 0;
|
||||
@@ -150,25 +151,22 @@ size_t rjp_search_members(const RJP_value* object, size_t num, const char** sear
|
||||
|
||||
for(;member;member = rjp_next_member(member),++objindex){
|
||||
for(size_t i = 0;i < num;++i){
|
||||
if(searches[i] == NULL)
|
||||
if(tmp[i] == NULL)
|
||||
continue;
|
||||
if(!strcmp(((RJP_object_member*)member)->name.value, searches[i])){
|
||||
if(!strcmp(((RJP_object_member*)member)->name.value, tmp[i])){
|
||||
dest[i].value = member;
|
||||
dest[i].searchindex = i;
|
||||
dest[i].objindex = objindex;
|
||||
searches[i] = NULL;
|
||||
tmp[i] = NULL;
|
||||
++matches;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(size_t i = 0;i < num;++i){
|
||||
searches[i] = tmp[i];
|
||||
}
|
||||
rjp_free(tmp);
|
||||
return matches;
|
||||
}
|
||||
RJP_search_res* rjp_search_members_multi(const RJP_value* object, size_t num, const char** searches, size_t* rsize, size_t skip){
|
||||
RJP_search_res* rjp_search_members_multi(const RJP_value* object, size_t num, const char* const* searches, size_t* rsize, size_t skip){
|
||||
RJP_search_res* ret = rjp_alloc(num*sizeof(RJP_search_res));
|
||||
size_t ret_size = num;
|
||||
size_t j = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
rjp
|
||||
Copyright (C) 2018 rexy712
|
||||
Copyright (C) 2018-2019 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
|
||||
@@ -148,7 +148,7 @@ static uint32_t u8_to_codepoint(char* u){
|
||||
}
|
||||
|
||||
//Convert escape sequences in strings
|
||||
char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, int* column){
|
||||
char* _rjp__parse_string(RJP_value* root, const char* str, int* inclen, int* len, int* row, int* column){
|
||||
char* new_string;
|
||||
++(*column); //account for starting quotation mark
|
||||
int oldpos = 0;
|
||||
@@ -173,7 +173,8 @@ char* _rjp__parse_string(RJP_value* root, const char* str, int* len, int* row, i
|
||||
*column = 0;
|
||||
}
|
||||
}
|
||||
*len = oldpos;
|
||||
*inclen = oldpos;
|
||||
*len = newpos;
|
||||
if(newpos == 0){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user