36 if (!
string)
return NULL;
38 string->text = (
char *)malloc(
sizeof(
char)*l);
45 strncpy(string->
text,s,l);
53 sprintf(buffer,
"%i",i);
60 sprintf(buffer,
"%f",f);
73 if (string->
text != NULL)
89 sj_set_error(
"sj_string_cmp: no character array provided");
92 return strncmp(string->
text,s,string->
size);
105 sj_set_error(
"sj_string_set: no character array provided");
109 if (l >= string->
size)
111 if (string->
text)free(string->
text);
112 string->text = (
char*)malloc(
sizeof(
char)*l);
115 sj_set_error(
"sj_string_set: failed to allocate space for resized string");
120 strncpy(string->
text,s,string->
size);
132 sj_set_error(
"sj_string_set: no character array provided");
135 if (l >= string->
size)
137 if (string->
text)free(string->
text);
138 string->text = (
char*)malloc(
sizeof(
char)*l);
141 sj_set_error(
"sj_string_set: failed to allocate space for resized string");
146 strncpy(string->
text,s,l);
147 string->text[l] =
'\0';
159 if (!json)
return NULL;
165 if (!json)
return NULL;
173 if (!
string)
return NULL;
175 if (!json)
return NULL;
186 if (!
string)
return NULL;
194 if ((!string1) || (!string2))
return;
195 size = string1->
size + string2->
size;
196 if (size <= 0)
return;
197 newtext=(
char *)malloc(
sizeof(
char)*size);
200 sj_set_error(
"sj_string_concat:failed to allocate space for new string\n");
203 memset(newtext,0,
sizeof(
char)*size);
204 snprintf(newtext,size,
"%s%s",string1->
text,string2->
text);
209 string1->
text = newtext;
210 string1->
size = size;
217 if ((!
string) || (!buffer))
return;
218 size =
string->size + strlen(buffer);
219 if (size <= 0)
return;
220 newtext=(
char *)malloc(
sizeof(
char)*size);
223 sj_set_error(
"sj_string_append:failed to allocate space for new string\n");
226 memset(newtext,0,
sizeof(
char)*size);
227 snprintf(newtext,size,
"%s%s",string->
text,buffer);
232 string->text = newtext;
239 if (!
string)
return NULL;
242 sj_set_error(
"sj_string_to_json_string: input string not a string type");
246 if (!json)
return NULL;
255 if (!
string)
return 0;
256 if (!string->
text)
return 0;
257 value = atoi(string->
text);
260 if (string->
text[0] !=
'0')
return 0;
272 if (!
string)
return 0;
273 if (!string->
text)
return 0;
274 value = atoi(string->
text);
277 if (string->
text[0] !=
'0')
return 0;
281 *output = (float)value;
288 if (!
string)
return 0;
289 if (!string->
text)
return 0;
290 if ((strcmp(string->
text,
"true")==0) ||
291 (strcmp(string->
text,
"TRUE")==0) ||
292 (strcmp(string->
text,
"True")==0) ||
293 (strcmp(string->
text,
"1\0")==0))
295 if (output)*output = 1;
298 if ((strcmp(string->
text,
"false")==0) ||
299 (strcmp(string->
text,
"FALSE")==0) ||
300 (strcmp(string->
text,
"False")==0) ||
301 (strcmp(string->
text,
"0\0")==0))
303 if (output)*output = 0;
SJString * sj_string_new_float(float f)
void sj_string_concat(SJString *string1, SJString *string2)
append the contents of string2 to string1
SJString * sj_string_to_json_string(SJson *string)
get the contents of the string back formatted and escaped for json
this is the abstract container structure for all json data This structure may be an object...
SJson * sj_new()
allocate a new empty json object
int sj_string_as_integer(SJString *string, int *output)
get the integer value if the string is a numer
void sj_string_set(SJString *string, char *s)
set the value of string to s
int sj_string_as_float(SJString *string, float *output)
get the float value if the string is a numer
SJString * sj_string_new_bool(int i)
void sj_string_set_limit(SJString *string, char *s, unsigned long l)
set the value of string to s but only length of s
char * sj_string_get_text(SJString *string)
get the text back from the string
SJString * sj_string_new()
make a new empty string
void sj_string_value_free(SJson *json)
char * sj_string_value_get_string(SJson *json)
void(* json_free)(struct SJson_S *json)
SJson * sj_string_to_value(SJString *string)
make a jason value object out of a string
void sj_set_error(char *er)
used internally to se the error message
SJson * sj_string_copy(SJson *json)
a basic structure that keeps track of a string and its length Automatically grows to accomodate longe...
SJString * sj_string_new_integer(int i)
int sj_string_as_bool(SJString *string, short int *output)
get the bool value if the string is a bool
SJson * sj_new_str(char *str)
make a new json value that is a string
void sj_string_free(SJString *string)
free an SJString
struct SJson_S *(* copy)(struct SJson_S *json)
int sj_string_cmp(SJString *string, char *s)
performs a strcmp on the string with the provided character array
void sj_string_append(SJString *string, char *buffer)
append the contents of buffer to the string
SJString * sj_string_new_text(char *s)
make a new string with the characters from array s
SJString *(* get_string)(struct SJson_S *json)