5 Commits
v0.6 ... v0.6.2

Author SHA1 Message Date
rexy712
50c7a055ec Updated version 2019-03-30 05:22:11 -07:00
rexy712
6771d00c6e Updated copyright notice 2019-03-30 05:20:53 -07:00
rexy712
71661cd9ad Made rjp_search_members take a 'const char* const*' for search terms 2019-03-30 04:37:06 -07:00
rexy712
46b7b56852 Fix rjp_string containing incorrect length 2019-02-21 10:49:21 -08:00
rexy712
fd7d9988b8 Fixed search return value being in an inconsistent state 2019-02-13 15:12:14 -08:00
10 changed files with 29 additions and 29 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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;
}