2 Commits
v0.6 ... v0.6.1

Author SHA1 Message Date
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
4 changed files with 11 additions and 8 deletions

View File

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

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

@@ -142,6 +142,7 @@ size_t rjp_search_members(const RJP_value* object, size_t num, const char** sear
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;

View File

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