Simple JSON  0.1
A free simple json library for C
simple_json_string.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SJString
 a basic structure that keeps track of a string and its length Automatically grows to accomodate longer strings More...
 

Functions

SJStringsj_string_new ()
 make a new empty string More...
 
SJStringsj_string_new_text (char *s)
 make a new string with the characters from array s More...
 
SJStringsj_string_new_integer (int i)
 
SJStringsj_string_new_float (float i)
 
SJStringsj_string_new_bool (int i)
 
void sj_string_free (SJString *string)
 free an SJString More...
 
int sj_string_cmp (SJString *string, char *s)
 performs a strcmp on the string with the provided character array More...
 
void sj_string_set (SJString *string, char *s)
 set the value of string to s More...
 
void sj_string_set_limit (SJString *string, char *s, unsigned long length)
 set the value of string to s but only length of s More...
 
void sj_string_concat (SJString *string1, SJString *string2)
 append the contents of string2 to string1 More...
 
void sj_string_append (SJString *string, char *buffer)
 append the contents of buffer to the string More...
 
char * sj_string_get_text (SJString *string)
 get the text back from the string More...
 
int sj_string_as_integer (SJString *string, int *output)
 get the integer value if the string is a numer More...
 
int sj_string_as_float (SJString *string, float *output)
 get the float value if the string is a numer More...
 
int sj_string_as_bool (SJString *string, short int *output)
 get the bool value if the string is a bool More...
 

Function Documentation

void sj_string_append ( SJString string,
char *  buffer 
)

append the contents of buffer to the string

Parameters
stringthe string to be added to
buffera NULL terminated character buffer. This will not be modified

Definition at line 213 of file simple_json_string.c.

int sj_string_as_bool ( SJString string,
short int *  output 
)

get the bool value if the string is a bool

Parameters
stringthe string to use as a bool
output[optional] where to store the boolean value. This is untouched if the string was not a bool
Returns
0 if the string was not an bool or 1 if it was

Definition at line 286 of file simple_json_string.c.

int sj_string_as_float ( SJString string,
float *  output 
)

get the float value if the string is a numer

Parameters
stringthe string to use as a float
output[optional] where to store the float value. This is untouched if the string was not a float
Returns
0 if the string was not an float or 1 if it was

Definition at line 269 of file simple_json_string.c.

int sj_string_as_integer ( SJString string,
int *  output 
)

get the integer value if the string is a numer

Parameters
stringthe string to use as an integer
output[optional] where to store the integer value. This is untouched if the string was not an integer
Returns
0 if the string was not an integer or 1 if it was

Definition at line 252 of file simple_json_string.c.

int sj_string_cmp ( SJString string,
char *  s 
)

performs a strcmp on the string with the provided character array

Parameters
stringthe SJString to check
sthe character array to compare with
Returns
<0 id string has a lower value than s, >0 if s has a lower value than string, 0 if they are equivalant

Definition at line 80 of file simple_json_string.c.

void sj_string_concat ( SJString string1,
SJString string2 
)

append the contents of string2 to string1

Parameters
string1this string will be modified by this operation
string2this string will NOT be modified by this operation

Definition at line 190 of file simple_json_string.c.

void sj_string_free ( SJString string)

free an SJString

Parameters
stringthe string to free

Definition at line 70 of file simple_json_string.c.

char* sj_string_get_text ( SJString string)

get the text back from the string

Parameters
stringthe string to get
Returns
NULL on error or the character array containing the string text

Definition at line 184 of file simple_json_string.c.

SJString* sj_string_new ( )

make a new empty string

Returns
NULL on error or a new string that must be freed with sj_string_free

Definition at line 8 of file simple_json_string.c.

SJString* sj_string_new_bool ( int  i)

Definition at line 64 of file simple_json_string.c.

SJString* sj_string_new_float ( float  i)

Definition at line 57 of file simple_json_string.c.

SJString* sj_string_new_integer ( int  i)

Definition at line 50 of file simple_json_string.c.

SJString* sj_string_new_text ( char *  s)

make a new string with the characters from array s

Parameters
sthe character array to populate the string with
Returns
NULL on error or a new string that must be freed with sj_string_free

Definition at line 26 of file simple_json_string.c.

void sj_string_set ( SJString string,
char *  s 
)

set the value of string to s

Parameters
stringthe string to change
sthe character array to change it to

Definition at line 95 of file simple_json_string.c.

void sj_string_set_limit ( SJString string,
char *  s,
unsigned long  length 
)

set the value of string to s but only length of s

Parameters
stringthe string to change
sthe character array to change it to
lengththe limit on characters to copy from s

Definition at line 123 of file simple_json_string.c.