json-gen-c
0.1.5
json-gen-c generate C code for json manipulation
|
Implementation of the sstr.h header file. More...
#include "sstr.h"
#include <assert.h>
#include <ctype.h>
#include <malloc.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
Macros | |
#define | STR struct sstr_s |
#define | SSTR(s) ((STR*)(s)) |
#define | STR_PTR(s) |
#define | SSTR_INT32_LEN (sizeof("-2147483648") - 1) |
#define | SSTR_INT64_LEN (sizeof("-9223372036854775808") - 1) |
#define | SSTR_MAX_UINT32_VALUE (uint32_t)0xffffffff |
#define | SSTR_MAX_INT32_VALUE (uint32_t)0x7fffffff |
Functions | |
sstr_t | sstr_new () |
Create an empty sstr_t. More... | |
void | sstr_free (sstr_t s) |
delete a sstr_t. More... | |
sstr_t | sstr_of (const void *data, size_t length) |
Create a sstr_t from data with length bytes. More... | |
sstr_t | sstr_ref (const void *data, size_t length) |
Create a sstr_t from data with length bytes. The data is not copied, but have a pointer to data. More... | |
sstr_t | sstr (const char *cstr) |
Create a sstr_t from C-style (NULL-terminated) string str. More... | |
char * | sstr_cstr (sstr_t s) |
Return C-style string representation of s. More... | |
int | sstr_compare (sstr_t a, sstr_t b) |
Compare a and b return 0 if equal, <0 if a < b, >0 if a > b. More... | |
int | sstr_compare_c (sstr_t a, const char *b) |
compare sstr_t a and c-style string b More... | |
void | sstr_append_zero (sstr_t s, size_t length) |
Extends the sstr_t by appending additional '\0' characters at the end of its current value. More... | |
void | sstr_append_of (sstr_t s, const void *data, size_t length) |
Extends the sstr_t by appending additional characters in data with length of length at the end of its current value . More... | |
void | sstr_append (sstr_t dst, sstr_t src) |
Extends the sstr_t by appending additional characters contained in src. More... | |
void | sstr_append_cstr (sstr_t dst, const char *src) |
Extends the sstr_t by appending additional characters contained in src. More... | |
sstr_t | sstr_dup (sstr_t s) |
Duplicate s and return. More... | |
sstr_t | sstr_substr (sstr_t s, size_t index, size_t len) |
Get substring of s starting at index with length bytes. More... | |
void | sstr_clear (sstr_t s) |
clear the sstr_t. After this call, the sstr_t is empty. More... | |
sstr_t | sstr_printf (const char *fmt,...) |
printf implement. More... | |
sstr_t | sstr_printf_append (sstr_t buf, const char *fmt,...) |
Same as sstr_printf(), but but print to buf instead of create a new one. More... | |
sstr_t | sstr_vslprintf (const char *fmt, va_list args) |
Printf implement. More... | |
sstr_t | sstr_vslprintf_append (sstr_t buf, const char *fmt, va_list args) |
Same as sstr_vslprintf, but print to buf instead of create a new one. More... | |
const char * | sstr_version () |
return version string. More... | |
void | sstr_append_int_str (sstr_t s, int i) |
convert sstr <-> int,long,float,double | |
int | sstr_parse_long (sstr_t s, long *v) |
int | sstr_parse_int (sstr_t *s, int *v) |
void | sstr_append_long_str (sstr_t s, long l) |
void | sstr_append_float_str (sstr_t s, float f, int precission) |
void | sstr_append_double_str (sstr_t s, double f, int precision) |
int | sstr_parse_double (sstr_t s, double *v) |
int | sstr_json_escape_string_append (sstr_t out, sstr_t in) |
void | sstr_append_of_if (sstr_t s, const void *data, size_t length, int cond) |
Append if cond is true, otherwise do nothing. More... | |
void | sstr_append_indent (sstr_t s, size_t indent) |
append spaces at the end of the sstr_t. More... | |
Implementation of the sstr.h header file.
#define STR_PTR | ( | s | ) |
sstr_t sstr | ( | const char * | cstr | ) |
Create a sstr_t from C-style (NULL-terminated) string str.
The cstr is copied to the new sstr_t, so you can free cstr after calling this function.
cstr | C-style string to copy to the result sstr_t. |
Extends the sstr_t by appending additional characters contained in src.
dst | destination sstr_t. |
src | source sstr_t. |
void sstr_append_cstr | ( | sstr_t | dst, |
const char * | src | ||
) |
Extends the sstr_t by appending additional characters contained in src.
dst | destination sstr_t. |
src | source C-style string. |
void sstr_append_indent | ( | sstr_t | s, |
size_t | indent | ||
) |
append spaces at the end of the sstr_t.
s | the sstr_t to append spaces to. |
indent | numbers of spaces to append. |
void sstr_append_of | ( | sstr_t | s, |
const void * | data, | ||
size_t | length | ||
) |
Extends the sstr_t by appending additional characters in data with length of length at the end of its current value .
s | destination sstr_t. |
data | data to append. |
length | length of data. |
void sstr_append_of_if | ( | sstr_t | s, |
const void * | data, | ||
size_t | length, | ||
int | cond | ||
) |
Append if cond is true, otherwise do nothing.
s | the sstr_t to append to. |
data | data to append. |
length | length of data. |
cond | condition |
void sstr_append_zero | ( | sstr_t | s, |
size_t | length | ||
) |
Extends the sstr_t by appending additional '\0' characters at the end of its current value.
s | destination sstr_t. |
length | length of '\0' to append. |
void sstr_clear | ( | sstr_t | s | ) |
clear the sstr_t. After this call, the sstr_t is empty.
s | sstr_t instance to clear. |
Compare a and b return 0 if equal, <0 if a < b, >0 if a > b.
a | sstr_t to be compared. |
b | sstr_t to be compared to. |
int sstr_compare_c | ( | sstr_t | a, |
const char * | b | ||
) |
compare sstr_t a and c-style string b
just like sstr_compare, but compare a and c-style string b.
char* sstr_cstr | ( | sstr_t | s | ) |
Return C-style string representation of s.
This function return a pointer to the internal C-style string, it has a null-terminal character at the end. So you can use it as a C-style string. The returned pointer is valid until sstr_free()/sstr_append()/sstr_append_of() or any functions that may modify the contents of sstr_t is called.
s | sstr_t instance to convert to C-style string. |
Duplicate s and return.
s | sstr_t to duplicate. |
void sstr_free | ( | sstr_t | s | ) |
delete a sstr_t.
s | sstr_t instance to delete. |
sstr_t sstr_new | ( | ) |
Create an empty sstr_t.
sstr_t sstr_of | ( | const void * | data, |
size_t | length | ||
) |
Create a sstr_t from data with length bytes.
The data is copied to the new sstr_t, so you can free data after calling this function.
data | data to copy to the result sstr_t. |
length | length of data. |
sstr_t sstr_printf | ( | const char * | fmt, |
... | |||
) |
printf implement.
fmt | format, like C printf() |
... | arguments, like C printf() |
Same as sstr_printf(), but but print to buf instead of create a new one.
buf | buffer to print to. |
fmt | format string. |
... | arguments. |
sstr_t sstr_ref | ( | const void * | data, |
size_t | length | ||
) |
Create a sstr_t from data with length bytes. The data is not copied, but have a pointer to data.
data | data of the result sstr_t. |
length | length of data. |
Get substring of s starting at index with length bytes.
s | sstr_t instance to get substring of. |
index | index of the first byte of the substring. |
len | number of bytes of the substring. |
const char* sstr_version | ( | ) |
return version string.
sstr_t sstr_vslprintf | ( | const char * | fmt, |
va_list | args | ||
) |
Printf implement.
supported formats:
reserved:
if u/x/X, tailing d can be ignore