Nilorea Library string api test.
char* chardest = NULL;
length = 0;
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
written = length = 0;
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
n_log(
LOG_INFO,
"charstr (%d/%d): %s", written, length, chardest);
nstrprintf(nstr,
"Hello, file is %s line %d date %s", __FILE__, __LINE__, __TIME__);
nstrprintf_cat(nstr,
" - This will be added at file %s line %d date %s", __FILE__, __LINE__, __TIME__);
nstrprintf(nstr,
"Hello, file is %s line %d date %s", __FILE__, __LINE__, __TIME__);
nstrprintf_cat(nstr,
" - This will be added at file %s line %d date %s", __FILE__, __LINE__, __TIME__);
char data[1048576] = "";
for (int it = 0; it < 1048575; it++) {
data[it] = (char)(32 + rand() % 63);
}
data[1048574] = '\0';
for (int it = 0; it < 100; it++) {
}
char* trimmed =
trim(
" spaces around ");
if (trimmed) {
}
char trimbuf[] = " hello ";
int ival = 0;
}
long int lval = 0;
}
long long int llval = 0;
}
char upper[32] = "";
char lower[32] = "";
strup(
"hello world", upper);
strlo(
"HELLO WORLD", lower);
char** parts =
split(
"one:two:three:four",
":", 0);
if (parts) {
for (int it = 0; it < count; it++) {
}
char* joined =
join(parts,
" - ");
if (joined) {
}
}
char* replaced =
str_replace(
"hello world hello",
"hello",
"bye");
if (replaced) {
}
char sanitize_buf[] = "hello; rm -rf /";
if (file_content) {
}
char skipbuf[] = " hello";
skipw(skipbuf,
' ', &it, 1);
n_log(
LOG_INFO,
"skipw past spaces: pos=%zu char='%c'", it, skipbuf[it]);
it = 0;
skipu(skipbuf,
'h', &it, 1);
n_log(
LOG_INFO,
"skipu to 'h': pos=%zu char='%c'", it, skipbuf[it]);
if (
scan_dir(
".", dir_list, 0) == TRUE) {
}
exit(0);
}
#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.