33 char* chardest = NULL;
38 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
40 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
42 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
44 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
46 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
48 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
54 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
56 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
58 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
60 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
62 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
64 n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
72 nstrprintf(nstr,
"Hello, file is %s line %d date %s", __FILE__, __LINE__, __TIME__);
76 nstrprintf_cat(nstr,
" - This will be added at file %s line %d date %s", __FILE__, __LINE__, __TIME__);
86 nstrprintf(nstr,
"Hello, file is %s line %d date %s", __FILE__, __LINE__, __TIME__);
90 nstrprintf_cat(nstr,
" - This will be added at file %s line %d date %s", __FILE__, __LINE__, __TIME__);
121 char data[1048576] =
"";
123 for (
int it = 0; it < 1048575; it++) {
124 data[it] = (char)(32 + rand() % 63);
126 data[1048574] =
'\0';
128 for (
int it = 0; it < 100; it++) {
142 char* trimmed =
trim(
" spaces around ");
148 char trimbuf[] =
" hello ";
158 if (
str_to_long(
"9876543210", &lval, 10) == TRUE) {
161 long long int llval = 0;
169 strup(
"hello world", upper);
171 strlo(
"HELLO WORLD", lower);
175 char** parts =
split(
"one:two:three:four",
":", 0);
179 for (
int it = 0; it < count; it++) {
182 char* joined =
join(parts,
" - ");
196 char* replaced =
str_replace(
"hello world hello",
"hello",
"bye");
203 char sanitize_buf[] =
"hello; rm -rf /";
218 char skipbuf[] =
" hello";
220 skipw(skipbuf,
' ', &it, 1);
221 n_log(
LOG_INFO,
"skipw past spaces: pos=%zu char='%c'", it, skipbuf[it]);
223 skipu(skipbuf,
'h', &it, 1);
224 n_log(
LOG_INFO,
"skipu to 'h': pos=%zu char='%c'", it, skipbuf[it]);
235 if (
scan_dir(
".", dir_list, 0) == TRUE) {
#define Free(__ptr)
Free Handler to get errors.
#define _nstr(__PTR)
N_STR or "NULL" string for logging purposes.
size_t nb_items
number of item currently in the list
int list_destroy(LIST **list)
Empty and Free a list container.
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
Structure of a generic LIST container.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
#define LOG_INFO
informational
size_t written
size of the written data inside the string
size_t length
length of string (in case we wanna keep information after the 0 end of string value)
int str_to_long_long(const char *s, long long int *i, const int base)
Helper for string to integer.
char * trim_nocopy(char *s)
trim and zero end the string, WARNING: keep and original pointer to delete the string correctly
size_t NSTRBYTE
N_STR base unit.
#define free_nstr(__ptr)
free a N_STR structure and set the pointer to NULL
int split_count(char **split_result)
Count split elements.
int nstr_to_file(N_STR *str, char *filename)
Write a N_STR content into a file.
char * join(char **splitresult, const char *delim)
join the array into a string
#define nstrcat(__nstr_dst, __nstr_src)
Macro to quickly concatenate two N_STR.
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
int strlo(const char *string, char *dest)
Lower case a string.
int write_and_fit(char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src)
concatenate a copy of src of size strlen( src ) to dest, starting at dest[ written ],...
#define nstrprintf_cat(__nstr_var, __format,...)
Macro to quickly allocate and sprintf and cat to a N_STR.
int resize_nstr(N_STR *nstr, size_t size)
reallocate a nstr internal buffer.
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
int skipu(const char *string, char toskip, NSTRBYTE *iterator, int inc)
skip until 'toskip' occurence is found from 'iterator' to the next 'toskip' value.
int empty_nstr(N_STR *nstr)
empty a N_STR string
int wildmatcase(register const char *text, register const char *p)
Written by Rich Salz rsalz at osf.org, refurbished by me.
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
char * str_replace(const char *string, const char *substr, const char *replacement)
Replace "substr" by "replacement" inside string taken from http://coding.debuntu.org/c-implementing-s...
char * trim(const char *s)
trim and put a \0 at the end, return new char *
int skipw(const char *string, char toskip, NSTRBYTE *iterator, int inc)
skip while 'toskip' occurence is found from 'iterator' to the next non 'toskip' position.
#define nstrprintf(__nstr_var, __format,...)
Macro to quickly allocate and sprintf to N_STR.
int scan_dir(const char *dir, LIST *result, const int recurse)
Scan a list of directory and return a list of char *file.
int str_sanitize(char *string, const char *mask, const char replacement)
clean a string by replacing evil characteres
char ** split(const char *str, const char *delim, int empty)
split the strings into a an array of char *pointer , ended by a NULL one.
int wildmat(register const char *text, register const char *p)
Written by Rich Salz rsalz at osf.org, refurbished by me.
int str_to_long(const char *s, long int *i, const int base)
Helper for string to integer.
int write_and_fit_ex(char **dest, NSTRBYTE *size, NSTRBYTE *written, const char *src, NSTRBYTE src_size, NSTRBYTE additional_padding)
concatenate a copy of src of size src_size to dest, starting at dest[ written ], updating written and...
N_STR * file_to_nstr(char *filename)
Load a whole file into a N_STR.
int free_split_result(char ***tab)
Free a split result allocated array.
int str_to_int(const char *s, int *i, const int base)
Helper for string to integer.
int strup(const char *string, char *dest)
Upper case a string.
A box including a string and his lenght.
N_STR and string function declaration.