Nilorea Library
C utilities for networking, threading, graphics
STRINGS: replacement to char *strings with dynamic resizing and boundary checking

Data Structures

struct  N_STR
 A box including a string and his lenght. More...
 

Macros

#define free_nstr(__ptr)
 free a N_STR structure and set the pointer to NULL More...
 
#define local_strdup(__src_)
 local strdup More...
 
#define n_remove_ending_cr(__nstr_var)
 Remove carriage return (backslash r) if there is one in the last position of the string. More...
 
#define n_replace_cr(__nstr_var, __replacement)
 Find and replace all occurences of carriage return (backslash r) in the string. More...
 
#define nstrprintf(__nstr_var, ...)
 Macro to quickly allocate and sprintf to N_STR *. More...
 
#define nstrprintf_cat(__nstr_var, ...)
 Macro to quickly allocate and sprintf and cat to a N_STR *. More...
 
#define resize_nstr(__nstr, new_size)
 Do tar(1) matching rules, which ignore a trailing slash? More...
 
#define strprintf(__n_var, ...)
 Macro to quickly allocate and sprintf to a char *. More...
 
#define WILDMAT_ABORT   -2
 Abort code to sped up pattern matching. More...
 
#define WILDMAT_NEGATE_CLASS   '^'
 What character marks an inverted character class? More...
 

Typedefs

typedef size_t NSTRBYTE
 N_STR base unit. More...
 

Functions

int _free_nstr (N_STR **ptr)
 Free a N_STR structure and set the pointer to NULL. More...
 
N_STRchar_to_nstr (const char *src)
 Convert a char into a N_STR, short version. More...
 
int char_to_nstr_ex (const char *from, NSTRBYTE nboct, N_STR **to)
 Convert a char into a N_STR, extended version. More...
 
N_STRchar_to_nstr_nocopy (char *src)
 Convert a char into a N_STR, direct use of linked source pointer, short version. More...
 
int char_to_nstr_nocopy_ex (char *from, NSTRBYTE nboct, N_STR **to)
 Convert a char into a N_STR, direct use of linked source pointer, extended version. More...
 
int empty_nstr (N_STR *nstr)
 empty a N_STR string More...
 
N_STRfile_to_nstr (char *filename)
 Load a whole file into a N_STR. More...
 
int free_nstr_nolog (N_STR **ptr)
 Free a N_STR structure and set the pointer to NULL. More...
 
void free_nstr_ptr (void *ptr)
 Free a N_STR pointer structure. More...
 
void free_nstr_ptr_nolog (void *ptr)
 Free a N_STR pointer structure. More...
 
int free_split_result (char ***tab)
 Free a split result allocated array. More...
 
char * join (char **splitresult, char *delim)
 join the array into a string More...
 
N_STRnew_nstr (NSTRBYTE size)
 create a new N_STR string More...
 
char * nfgets (char *buffer, NSTRBYTE size, FILE *stream)
 try to fgets More...
 
int nstr_to_fd (N_STR *str, FILE *out, int lock)
 Write a N_STR content into a file. More...
 
int nstr_to_file (N_STR *n_str, char *filename)
 Write a N_STR content into a file. More...
 
int nstrcat (N_STR *dst, N_STR *src)
 Add N_STR *src content to N_STR *dst, resizing it if needed. More...
 
int nstrcat_bytes (N_STR *dest, void *src)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
int nstrcat_bytes_ex (N_STR *dest, void *src, NSTRBYTE size)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
int nstrcat_ex (N_STR *dest, void *src, NSTRBYTE size, int resize_flag)
 Append data into N_STR using internal N_STR size and cursor position. More...
 
N_STRnstrdup (N_STR *msg)
 Duplicate a N_STR. More...
 
int scan_dir (const char *dir, LIST *result, const int recurse)
 Scan a list of directory and return a list of char *file. More...
 
int scan_dir_ex (const char *dir, const char *pattern, LIST *result, const int recurse, const int mode)
 Scan a list of directory and return a list of char *file. More...
 
int skipu (char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip until 'toskip' occurence is found from 'iterator' to the next 'toskip' value. More...
 
int skipw (char *string, char toskip, NSTRBYTE *iterator, int inc)
 skip while 'toskip' occurence is found from 'iterator' to the next non 'toskip' position. More...
 
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. More...
 
int split_count (char **split_result)
 Count split elements. More...
 
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-str_replace-replace-all-occurrences-substring By Chantra. More...
 
int str_sanitize (char *string, const char *mask, const char replacement)
 clean a string by replacing evil characteres More...
 
int str_sanitize_ex (char *string, const NSTRBYTE string_len, const char *mask, const NSTRBYTE masklen, const char replacement)
 clean a string by replacing evil characteres More...
 
int str_to_int (const char *s, int *i, const int base)
 Helper for string to integer. More...
 
int str_to_int_ex (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base)
 Helper for string[start to end] to integer. More...
 
int str_to_int_nolog (const char *s, NSTRBYTE start, NSTRBYTE end, int *i, const int base, N_STR **infos)
 Helper for string[start to end] to integer. More...
 
int str_to_long (const char *s, long int *i, const int base)
 Helper for string to integer. More...
 
int str_to_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long int *i, const int base)
 Helper for string[start to end] to long integer. More...
 
int str_to_long_long (const char *s, long long int *i, const int base)
 Helper for string to integer. More...
 
int str_to_long_long_ex (const char *s, NSTRBYTE start, NSTRBYTE end, long long int *i, const int base)
 Helper for string[start to end] to long long integer. More...
 
int strcpy_u (char *from, char *to, NSTRBYTE to_size, char split, NSTRBYTE *it)
 Copy from start to dest until from[ iterator ] == split. More...
 
int strlo (char *string, char *dest)
 Upper case a string. More...
 
int strup (char *string, char *dest)
 Upper case a string. More...
 
char * trim (char *s)
 trim and put a \0 at the end, return new char * More...
 
char * trim_nocopy (char *s)
 trim and zero end the string, WARNING: keep and original pointer to delete the string correctly More...
 
int wildmat (register const char *text, register const char *p)
 Written by Rich Salz rsalz at osf.org, refurbished by me. More...
 
int wildmatcase (register const char *text, register const char *p)
 Written by Rich Salz rsalz at osf.org, refurbished by me. More...
 
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 ], updating written and size variable, allocation of new blocks of (needed size + 512) if resize is needed. More...
 
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 size variable, allocation of new blocks of (needed size + additional_padding ) if resize is needed. More...
 

Detailed Description


Data Structure Documentation

◆ N_STR

struct N_STR

A box including a string and his lenght.

Examples
ex_base64.c, ex_common.c, ex_crypto.c, ex_fluid.c, ex_gui_particles.c, ex_hash.c, ex_list.c, ex_monolith.c, ex_network.c, and ex_nstr.c.

Definition at line 172 of file n_str.h.

+ Collaboration diagram for N_STR:
Data Fields
char * data the string
size_t length length of string (in case we wanna keep information after the 0 end of string value)
size_t written size of the written data inside the string

Macro Definition Documentation

◆ free_nstr

#define free_nstr (   __ptr)
Value:
{ \
if( (*__ptr ) ) \
{ \
_free_nstr( __ptr ); \
} \
else \
{ \
n_log( LOG_DEBUG , "%s is already NULL" , #__ptr ); \
} \
}
#define LOG_DEBUG
debug-level messages
Definition: n_log.h:66

free a N_STR structure and set the pointer to NULL

Examples
ex_base64.c, ex_common.c, ex_crypto.c, ex_fluid.c, ex_gui_particles.c, ex_hash.c, ex_list.c, ex_monolith.c, ex_network.c, and ex_nstr.c.

Definition at line 222 of file n_str.h.

◆ local_strdup

#define local_strdup (   __src_)
Value:
({ \
char *str = NULL ;\
int len = strlen( (__src_) );\
Malloc( str , char , len + 5 );\
if( !str )\
{ \
n_log( LOG_ERR , "Couldn't allocate %d byte for duplicating \"%s\"" , (__src_) );\
}\
else\
{\
for( int it = 0 ; it <= len ; it ++ )\
{\
str[ it ] = (__src_)[ it ] ;\
}\
}\
str ;\
})
#define LOG_ERR
error conditions
Definition: n_log.h:58

local strdup

Definition at line 37 of file n_str.h.

◆ n_remove_ending_cr

#define n_remove_ending_cr (   __nstr_var)
Value:
if( __nstr_var && __nstr_var -> data && __nstr_var -> data[ __nstr_var -> written ] == '\r' ) \
{ \
__nstr_var -> data[ __nstr_var -> written ] = '\0' ; \
__nstr_var -> written -- ; \
}

Remove carriage return (backslash r) if there is one in the last position of the string.

Definition at line 144 of file n_str.h.

◆ n_replace_cr

#define n_replace_cr (   __nstr_var,
  __replacement 
)
Value:
if( __nstr_var && __nstr_var -> data && __nstr_var -> written > 0 ) \
{ \
char *__replaced = str_replace( __nstr_var -> data , "\r" , __replacement ); \
if( __replaced ) \
{ \
Free( __nstr_var -> data ); \
__nstr_var -> data = __replaced ; \
__nstr_var -> written = strlen( __nstr_var -> data ); \
__nstr_var -> length = __nstr_var -> written + 1 ; \
} \
}
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...
Definition: n_str.c:1598

Find and replace all occurences of carriage return (backslash r) in the string.

Definition at line 154 of file n_str.h.

◆ nstrprintf

#define nstrprintf (   __nstr_var,
  ... 
)
Value:
({ \
if( __nstr_var ) \
{ \
free_nstr( &__nstr_var ); \
}\
NSTRBYTE needed = 0 ; \
needed = snprintf( NULL , 0 , __VA_ARGS__ ); \
__nstr_var = new_nstr( needed + 1 ); \
if( __nstr_var )\
{ \
snprintf( __nstr_var -> data , needed + 1 , __VA_ARGS__ ); \
__nstr_var -> written = needed ; \
} \
__nstr_var ; \
})
N_STR * new_nstr(NSTRBYTE size)
create a new N_STR string
Definition: n_str.c:215

Macro to quickly allocate and sprintf to N_STR *.

Examples
ex_base64.c, ex_crypto.c, ex_fluid.c, ex_gui_particles.c, ex_hash.c, ex_list.c, ex_monolith.c, and ex_nstr.c.

Definition at line 97 of file n_str.h.

◆ nstrprintf_cat

#define nstrprintf_cat (   __nstr_var,
  ... 
)
Value:
({ \
if( __nstr_var ) \
{ \
int needed_size = 0 ; \
needed_size = snprintf( NULL , 0 , __VA_ARGS__ ); \
if( needed_size > 0 ) \
{ \
NSTRBYTE needed = needed_size + 1 ; \
if( ( __nstr_var -> written + needed ) > __nstr_var -> length ) \
{ \
resize_nstr( __nstr_var , __nstr_var -> length + needed ); \
} \
snprintf( __nstr_var -> data + __nstr_var -> written , needed , __VA_ARGS__ ); \
__nstr_var -> written += needed_size ; \
} \
else \
{ \
nstrprintf( __nstr_var , __VA_ARGS__ ); \
} \
} \
__nstr_var ; \
} )

Macro to quickly allocate and sprintf and cat to a N_STR *.

Examples
ex_monolith.c, and ex_nstr.c.

Definition at line 117 of file n_str.h.

◆ resize_nstr

#define resize_nstr (   __nstr,
  new_size 
)
Value:
({ \
if( __nstr && __nstr -> data ) \
{ \
Reallocz( __nstr -> data , char , __nstr -> length , new_size ); \
__nstr -> length = new_size ; \
} \
})

Do tar(1) matching rules, which ignore a trailing slash?

Macro to quickly realloc a n_str

Definition at line 65 of file n_str.h.

◆ strprintf

#define strprintf (   __n_var,
  ... 
)
Value:
({ \
if( !__n_var ) \
{ \
NSTRBYTE needed = 0 ; \
needed = snprintf( NULL , 0 , __VA_ARGS__ ); \
Malloc( __n_var , char , needed + 2 );\
if( __n_var )\
{ \
snprintf( __n_var , needed + 1 , __VA_ARGS__ ); \
} \
} \
else \
{ \
n_log( LOG_ERR , "%s is already allocated." , "#__n_var" ); \
} \
__n_var ; \
})

Macro to quickly allocate and sprintf to a char *.

Definition at line 77 of file n_str.h.

◆ WILDMAT_ABORT

#define WILDMAT_ABORT   -2

Abort code to sped up pattern matching.

Special thanks to Lars Mathiesen thori.nosp@m.nn@d.nosp@m.iku.d.nosp@m.k for the ABORT code.

Definition at line 58 of file n_str.h.

◆ WILDMAT_NEGATE_CLASS

#define WILDMAT_NEGATE_CLASS   '^'

What character marks an inverted character class?

Definition at line 60 of file n_str.h.

Typedef Documentation

◆ NSTRBYTE

typedef size_t NSTRBYTE

N_STR base unit.

Definition at line 169 of file n_str.h.

Function Documentation

◆ _free_nstr()

int _free_nstr ( N_STR **  ptr)

Free a N_STR structure and set the pointer to NULL.

Parameters
ptrA N_STR *object to free
Returns
TRUE or FALSE

Definition at line 72 of file n_str.c.

References __n_assert, and FreeNoLog.

◆ char_to_nstr()

N_STR * char_to_nstr ( const char *  src)

Convert a char into a N_STR, short version.

Parameters
srcA char *string to convert
Returns
A N_STR copy of src or NULL

Definition at line 273 of file n_str.c.

References char_to_nstr_ex().

Referenced by add_strdup_to_msg(), n_get_cpu_id(), n_vigenere_quick_decode(), and n_vigenere_quick_encode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ char_to_nstr_ex()

int char_to_nstr_ex ( const char *  from,
NSTRBYTE  nboct,
N_STR **  to 
)

Convert a char into a N_STR, extended version.

Parameters
fromA char *string to convert
nboctThe size to copy, from 1 octet to nboctet (ustrsizez( from ) )
toA N_STR pointer who will be Malloced
Returns
True on success, FALSE on failure ( to will be set to NULL )

Definition at line 246 of file n_str.c.

References __n_assert, _str, Free, LOG_ERR, n_log, and new_nstr().

Referenced by char_to_nstr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ char_to_nstr_nocopy()

N_STR * char_to_nstr_nocopy ( char *  src)

Convert a char into a N_STR, direct use of linked source pointer, short version.

Parameters
srcA char *string to convert
Returns
A N_STR copy of src or NULL

Definition at line 318 of file n_str.c.

References char_to_nstr_nocopy_ex().

+ Here is the call graph for this function:

◆ char_to_nstr_nocopy_ex()

int char_to_nstr_nocopy_ex ( char *  from,
NSTRBYTE  nboct,
N_STR **  to 
)

Convert a char into a N_STR, direct use of linked source pointer, extended version.

Parameters
fromA char *string to convert
nboctThe size to copy, from 1 octet to nboctet (ustrsizez( from ) )
toA N_STR pointer who will be Malloced
Returns
True on success, FALSE on failure ( to will be set to NULL )

Definition at line 289 of file n_str.c.

References __n_assert, _str, Free, LOG_ERR, n_log, and new_nstr().

Referenced by char_to_nstr_nocopy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty_nstr()

int empty_nstr ( N_STR nstr)

empty a N_STR string

Parameters
nstrthe N_STR *str string to empty
Returns
TRUE or FALSE

Definition at line 199 of file n_str.c.

References __n_assert.

◆ file_to_nstr()

N_STR * file_to_nstr ( char *  filename)

Load a whole file into a N_STR.

Be aware of the NSTRBYTE addressing limit (2GB commonly)

Parameters
filenameThe filename to load inside a N_STR
Returns
A valid N_STR or NULL

Definition at line 332 of file n_str.c.

References __n_assert, free_nstr, LOG_DEBUG, LOG_ERR, n_log, and new_nstr().

Referenced by n_kafka_load_config(), n_kafka_new_event_from_file(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_nstr_nolog()

int free_nstr_nolog ( N_STR **  ptr)

Free a N_STR structure and set the pointer to NULL.

Parameters
ptrA N_STR *object to free
Returns
TRUE or FALSE

Definition at line 89 of file n_str.c.

References FreeNoLog.

◆ free_nstr_ptr()

void free_nstr_ptr ( void *  ptr)

Free a N_STR pointer structure.

Parameters
ptrA N_STR *object to free

Definition at line 55 of file n_str.c.

References FreeNoLog.

Referenced by add_nstrdup_to_msg(), add_nstrptr_to_msg(), add_strdup_to_msg(), n_kafka_poll(), netw_add_msg(), netw_add_msg_ex(), netw_recv_func(), and scan_dir_ex().

+ Here is the caller graph for this function:

◆ free_nstr_ptr_nolog()

void free_nstr_ptr_nolog ( void *  ptr)

Free a N_STR pointer structure.

Parameters
ptrA N_STR *object to free

Definition at line 107 of file n_str.c.

References FreeNoLog.

◆ free_split_result()

int free_split_result ( char ***  tab)

Free a split result allocated array.

Parameters
tabA pointer to a split result to free
Returns
TRUE

Definition at line 1131 of file n_str.c.

References Free.

Referenced by load_config_file(), n_kafka_delivery_message_callback(), and split().

+ Here is the caller graph for this function:

◆ join()

char * join ( char **  splitresult,
char *  delim 
)

join the array into a string

Parameters
splitresultthe split result to join
delimThe delimiter, one or more characters
Returns
the joined split result or NULL

Definition at line 1153 of file n_str.c.

References Malloc.

Referenced by n_kafka_load_config(), and n_kafka_pooling_thread().

+ Here is the caller graph for this function:

◆ new_nstr()

N_STR * new_nstr ( NSTRBYTE  size)

create a new N_STR string

Parameters
sizeSize of the new string. 0 for no allocation.
Returns
A new allocated N_STR or NULL

Definition at line 215 of file n_str.c.

References __n_assert, Free, and Malloc.

Referenced by char_to_nstr_ex(), char_to_nstr_nocopy_ex(), file_to_nstr(), n_base64_decode(), n_base64_encode(), n_kafka_dump_unprocessed(), n_kafka_load_config(), n_kafka_new(), n_popen(), n_vigenere_get_answer(), n_vigenere_get_question(), n_vigenere_get_rootkey(), nstrdup(), send_net_datas(), unzip_nstr(), and zip_nstr().

+ Here is the caller graph for this function:

◆ nfgets()

char * nfgets ( char *  buffer,
NSTRBYTE  size,
FILE *  stream 
)

try to fgets

Parameters
bufferThe string where to read the file
sizeSize of the string
streamThe file to read
Returns
NULL or the captured string

Definition at line 172 of file n_str.c.

References __n_assert, LOG_DEBUG, and n_log.

◆ nstr_to_fd()

int nstr_to_fd ( N_STR str,
FILE *  out,
int  lock 
)

Write a N_STR content into a file.

Parameters
strThe N_STR *content to write down
outAn opened FILE *handler
locka write lock will be put if lock = 1
Returns
TRUE or FALSE

Definition at line 402 of file n_str.c.

References __n_assert, LOG_ERR, and n_log.

Referenced by nstr_to_file().

+ Here is the caller graph for this function:

◆ nstr_to_file()

int nstr_to_file ( N_STR str,
char *  filename 
)

Write a N_STR content into a file.

Parameters
strThe N_STR *content to write down
filenameThe destination filename
Returns
TRUE or FALSE

Definition at line 459 of file n_str.c.

References __n_assert, _str, LOG_DEBUG, n_log, and nstr_to_fd().

Referenced by n_kafka_dump_unprocessed(), n_vigenere_decode_file(), n_vigenere_decode_file_qa(), n_vigenere_encode_file(), and n_vigenere_encode_file_qa().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrcat()

int nstrcat ( N_STR dst,
N_STR src 
)

Add N_STR *src content to N_STR *dst, resizing it if needed.

Parameters
dstThe N_STR *destination
srcThe N_STR *source to concatenate into dst
Returns
TRUE or FALSE

Definition at line 1246 of file n_str.c.

References nstrcat_ex().

+ Here is the call graph for this function:

◆ nstrcat_bytes()

int nstrcat_bytes ( N_STR dest,
void *  data 
)

Append data into N_STR using internal N_STR size and cursor position.

Wrapper to nstrcat_ex, with resize_flag on and a block size one byte higher than size.

Parameters
destThe N_STR *destination (accumulator)
dataThe data to append
Returns
TRUE or FALSE

Definition at line 1281 of file n_str.c.

References __n_assert, LOG_ERR, n_log, and nstrcat_bytes_ex().

+ Here is the call graph for this function:

◆ nstrcat_bytes_ex()

int nstrcat_bytes_ex ( N_STR dest,
void *  data,
NSTRBYTE  size 
)

Append data into N_STR using internal N_STR size and cursor position.

Wrapper to nstrcat_ex, with resize_flag on and a block size one byte higher than size.

Parameters
destThe N_STR *destination (accumulator)
dataThe data to append
sizeThe number of octet of data we want to append in dest
Returns
TRUE or FALSE

Definition at line 1260 of file n_str.c.

References __n_assert, LOG_ERR, n_log, and nstrcat_ex().

Referenced by nstrcat_bytes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrcat_ex()

int nstrcat_ex ( N_STR dest,
void *  src,
NSTRBYTE  size,
int  resize_flag 
)

Append data into N_STR using internal N_STR size and cursor position.

Parameters
destThe N_STR *destination (accumulator)
srcThe data to append
sizeThe number of octet of data we want to append in dest
resize_flagSet it to a positive non zero value to allow resizing, or to zero to forbid resizing
Returns
TRUE or FALSE

Definition at line 1198 of file n_str.c.

References __n_assert, Free, LOG_ERR, n_log, and Reallocz.

Referenced by nstrcat(), and nstrcat_bytes_ex().

+ Here is the caller graph for this function:

◆ nstrdup()

N_STR * nstrdup ( N_STR str)

Duplicate a N_STR.

Parameters
strA N_STR *object to free
Returns
A valid N_STR or NULL

Definition at line 795 of file n_str.c.

References __n_assert, Free, LOG_ERR, n_log, and new_nstr().

Referenced by add_nstrdup_to_msg(), n_vigenere_cypher(), netmsg_make_string_msg(), netw_pool_broadcast(), and userlist_add_msg_to_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scan_dir()

int scan_dir ( const char *  dir,
LIST result,
const int  recurse 
)

Scan a list of directory and return a list of char *file.

Parameters
dirThe directory to scan
resultA pointer to a valid LIST for the results
recurseRecursive search if TRUE, directory only if FALSE
Returns
TRUE or FALSE

Definition at line 1363 of file n_str.c.

References scan_dir_ex().

+ Here is the call graph for this function:

◆ scan_dir_ex()

int scan_dir_ex ( const char *  dir,
const char *  pattern,
LIST result,
const int  recurse,
const int  mode 
)

Scan a list of directory and return a list of char *file.

Parameters
dirThe directory to scan
patternPattern that files must follow to figure in the list
resultA pointer to a valid LIST for the results
recurseRecursive search if TRUE, directory only if FALSE
mode0 for a list of char* , 1 for a list of N_STR *
Returns
TRUE or FALSE

Definition at line 1379 of file n_str.c.

References free_nstr, free_nstr_ptr(), list_push(), LOG_ERR, n_log, nstrprintf, scan_dir_ex(), and wildmatcase().

Referenced by scan_dir(), and scan_dir_ex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipu()

int skipu ( char *  string,
char  toskip,
NSTRBYTE iterator,
int  inc 
)

skip until 'toskip' occurence is found from 'iterator' to the next 'toskip' value.

The new iterator index is automatically stored, returning to it first value if an error append.

Parameters
stringa char *stri:wqng to search in
toskipskipping while char character 'toskip' isnt found
iteratoran int iteraor position on the string
incan int to specify the step of skipping
Returns
TRUE if success FALSE or ABORT if not

Definition at line 889 of file n_str.c.

References __n_assert.

Referenced by load_config_file().

+ Here is the caller graph for this function:

◆ skipw()

int skipw ( char *  string,
char  toskip,
NSTRBYTE iterator,
int  inc 
)

skip while 'toskip' occurence is found from 'iterator' to the next non 'toskip' position.

The new iterator index is automatically stored, returning to it first value if an error append.

Parameters
stringa char *string to search in
toskipskipping while char character 'toskip' is found
iteratoran int iteraor position on the string
incan int to specify the step of skipping
Returns
TRUE if success FALSE or ABORT if not

Definition at line 835 of file n_str.c.

References __n_assert.

◆ split()

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.

Parameters
strThe char *str to split
delimThe delimiter, one or more characters
emptyEmpty flag. If 1, then empty delimited areas will be added as NULL entries, else they will be skipped.
Returns
An array of char *, ended by a NULL entry.

Definition at line 1032 of file n_str.c.

References __n_assert, free_split_result(), and Malloc.

Referenced by n_kafka_delivery_message_callback(), n_kafka_load_config(), and strcpy_u().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ split_count()

int split_count ( char **  split_result)

Count split elements.

Parameters
split_resultA char **result from a split call
Returns
a joined string using delimiter with The number of elements or -1 if errors

Definition at line 1111 of file n_str.c.

References __n_assert.

Referenced by load_config_file(), n_kafka_delivery_message_callback(), and n_kafka_load_config().

+ Here is the caller graph for this function:

◆ str_replace()

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-str_replace-replace-all-occurrences-substring By Chantra.

Parameters
stringOriginal string to modify
substrString to search
replacementSubstitution string
Returns
A copy of the sustituted string or NULL

Definition at line 1598 of file n_str.c.

References Malloc.

Referenced by load_config_file().

+ Here is the caller graph for this function:

◆ str_sanitize()

int str_sanitize ( char *  string,
const char *  mask,
const char  replacement 
)

clean a string by replacing evil characteres

Parameters
stringThe string to change
maskThe caracters to kill
replacementreplacement for mask
Returns
TRUE or FALSE

Definition at line 1667 of file n_str.c.

References str_sanitize_ex().

+ Here is the call graph for this function:

◆ str_sanitize_ex()

int str_sanitize_ex ( char *  string,
const NSTRBYTE  string_len,
const char *  mask,
const NSTRBYTE  masklen,
const char  replacement 
)

clean a string by replacing evil characteres

Parameters
stringThe string to change
string_lenSize of the data to treat
maskThe caracters to kill
masklensize of mask
replacementreplacement for mask
Returns
TRUE or FALSE

Definition at line 1640 of file n_str.c.

References __n_assert.

Referenced by str_sanitize().

+ Here is the caller graph for this function:

◆ str_to_int()

int str_to_int ( const char *  s,
int *  i,
const int  base 
)

Helper for string to integer.

Parameters
sString to convert
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 592 of file n_str.c.

References str_to_int_ex().

+ Here is the call graph for this function:

◆ str_to_int_ex()

int str_to_int_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
int *  i,
const int  base 
)

Helper for string[start to end] to integer.

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 492 of file n_str.c.

References __n_assert, Free, LOG_ERR, Malloc, and n_log.

Referenced by str_to_int().

+ Here is the caller graph for this function:

◆ str_to_int_nolog()

int str_to_int_nolog ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
int *  i,
const int  base,
N_STR **  infos 
)

Helper for string[start to end] to integer.

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
infosIf not NULL , contain the errors. remember to free the pointer if returned !!
Returns
TRUE or FALSE

Definition at line 545 of file n_str.c.

References __n_assert, Free, LOG_ERR, Malloc, n_log, and nstrprintf.

◆ str_to_long()

int str_to_long ( const char *  s,
long int *  i,
const int  base 
)

Helper for string to integer.

Parameters
sString to convert
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 759 of file n_str.c.

References str_to_long_ex().

+ Here is the call graph for this function:

◆ str_to_long_ex()

int str_to_long_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
long int *  i,
const int  base 
)

Helper for string[start to end] to long integer.

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 615 of file n_str.c.

References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.

Referenced by str_to_long().

+ Here is the caller graph for this function:

◆ str_to_long_long()

int str_to_long_long ( const char *  s,
long long int *  i,
const int  base 
)

Helper for string to integer.

Parameters
sString to convert
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 778 of file n_str.c.

References str_to_long_long_ex().

+ Here is the call graph for this function:

◆ str_to_long_long_ex()

int str_to_long_long_ex ( const char *  s,
NSTRBYTE  start,
NSTRBYTE  end,
long long int *  i,
const int  base 
)

Helper for string[start to end] to long long integer.

Automatically add /0 for conversion. Leave values untouched if any error occur. Work on a copy of the chunk.

Parameters
sString to convert
startStart position of the chunk
endEnd position of the chunk
iA pointer to an integer variable which will receieve the value.
baseBase for converting values
Returns
TRUE or FALSE

Definition at line 688 of file n_str.c.

References __n_assert, Free, LOG_DEBUG, LOG_ERR, Malloc, and n_log.

Referenced by str_to_long_long().

+ Here is the caller graph for this function:

◆ strcpy_u()

int strcpy_u ( char *  from,
char *  to,
NSTRBYTE  to_size,
char  split,
NSTRBYTE it 
)

Copy from start to dest until from[ iterator ] == split.

Parameters
fromSource string
toDest string
to_sizethe maximum size to write
splitstopping character
itSave of iterator
Returns
TRUE or FALSE

Definition at line 990 of file n_str.c.

References __n_assert, LOG_DEBUG, n_log, and split().

+ Here is the call graph for this function:

◆ strlo()

int strlo ( char *  string,
char *  dest 
)

Upper case a string.

Parameters
stringthe string to change to lower case
destthe string where storing result
Warning
string must be same size as dest
Returns
TRUE or FALSE

Definition at line 965 of file n_str.c.

References __n_assert.

◆ strup()

int strup ( char *  string,
char *  dest 
)

Upper case a string.

Parameters
stringthe string to change to upper case
destthe string where storing result
Warning
string must be same size as dest
Returns
TRUE or FALSE

Definition at line 942 of file n_str.c.

References __n_assert.

◆ trim()

char * trim ( char *  s)

trim and put a \0 at the end, return new char *

Parameters
sThe string to trim
Returns
the trimmed string or NULL

Definition at line 156 of file n_str.c.

References __n_assert, and trim_nocopy().

+ Here is the call graph for this function:

◆ trim_nocopy()

char * trim_nocopy ( char *  s)

trim and zero end the string, WARNING: keep and original pointer to delete the string correctly

Parameters
sThe string to trim
Returns
the trimmed string or NULL

Definition at line 124 of file n_str.c.

References __n_assert.

Referenced by load_config_file(), and trim().

+ Here is the caller graph for this function:

◆ wildmat()

int wildmat ( register const char *  text,
register const char *  p 
)

Written by Rich Salz rsalz at osf.org, refurbished by me.

Wildcard pattern matching .

Parameters
textThe source text to search
pThe text to search, with wildcards
Returns
return TRUE, FALSE, or WILDMAT_ABORT.

Definition at line 1459 of file n_str.c.

References wildmat(), WILDMAT_ABORT, and WILDMAT_NEGATE_CLASS.

Referenced by wildmat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wildmatcase()

int wildmatcase ( register const char *  text,
register const char *  p 
)

Written by Rich Salz rsalz at osf.org, refurbished by me.

Wildcard pattern matching case insensitive.

Parameters
textThe source text to search
pThe text to search, with wildcards
Returns
return TRUE, FALSE, or WILDMAT_ABORT.

Definition at line 1527 of file n_str.c.

References WILDMAT_ABORT, WILDMAT_NEGATE_CLASS, and wildmatcase().

Referenced by scan_dir_ex(), and wildmatcase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_and_fit()

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 ], updating written and size variable, allocation of new blocks of (needed size + 512) if resize is needed.

If dest is NULL it will be allocated.

Parameters
destThe dest string
sizeThe current size, will be updated if written + strlen( dest) > size
writtenthe number of octet added
srcThe source string to add
Returns
TRUE on success or FALSE on a realloc error

Definition at line 1349 of file n_str.c.

References write_and_fit_ex().

+ Here is the call graph for this function:

◆ write_and_fit_ex()

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 size variable, allocation of new blocks of (needed size + additional_padding ) if resize is needed.

If dest is NULL it will be allocated.

Parameters
destThe dest string
sizeThe current size, will be updated if written + strlen( dest) > size
writtenthe number of octet added
srcThe source string to add
src_sizeThe source string size
additional_paddingIn case the destination is reallocated, number of additional bytes that will be added (provisionning)
Returns
TRUE on success or FALSE on a realloc error

Definition at line 1310 of file n_str.c.

References LOG_ERR, n_log, and Reallocz.

Referenced by write_and_fit().

+ Here is the caller graph for this function: