Functions
string.h File Reference

String utils. More...

Functions

VTM_API char * vtm_str_copy (const char *in)
 
VTM_API char * vtm_str_ncopy (const char *in, size_t len)
 
VTM_API int vtm_str_casecmp (const char *s1, const char *s2)
 
VTM_API vtm_list * vtm_str_split (const char *in, const char *delim, unsigned int count)
 
VTM_API int vtm_str_split_ex (const char *in, const char *delim, char ***out_tokens, size_t *token_count)
 
VTM_API char * vtm_str_trim (char *in)
 
VTM_API char * vtm_str_printf (const char *fmt,...)
 
VTM_API char * vtm_str_vprintf (const char *fmt, va_list ap)
 
VTM_API ssize_t vtm_str_index_of (const char *in, char c, size_t len)
 
VTM_API ssize_t vtm_str_index_chars (const char *in, size_t len, char *chars, size_t char_count, char *out_found)
 
VTM_API ssize_t vtm_str_index_pattern (const char *in, const char *pattern, size_t input_len, size_t pattern_len)
 
VTM_API bool vtm_str_list_contains (const char *in, const char *delim, const char *search, bool nocase)
 
VTM_API size_t vtm_str_pattern_count (const char *in, const char *pattern)
 
VTM_API bool vtm_str_starts_with (const char *in, const char *start)
 

Function Documentation

VTM_API char* vtm_str_copy ( const char *  in)

Returns a copy of the input string.

Parameters
inthe string that should be copied
Returns
a copy of the string
NULL if not enough memory could be allocated
VTM_API char* vtm_str_ncopy ( const char *  in,
size_t  len 
)

Returns a copy of the first n characters of the input string.

Parameters
inthe input string
lenthe number of bytes that should be copied
Returns
a copy of the first n bytes
NULL if not enough memory could be allocated
VTM_API int vtm_str_casecmp ( const char *  s1,
const char *  s2 
)

Compares s1 to s2 ignoring case.

Parameters
s1
s2
Returns
-1 if first character of s1 that does not match is lesser than the coresponding character from s2
0 if the strings are equal
1 if the first character of s1 that does not match is greater than the corresponding character from s2
VTM_API vtm_list* vtm_str_split ( const char *  in,
const char *  delim,
unsigned int  count 
)

Splits the given input string by given delimiter

Parameters
inthe input string
delimthe delimiter by that the input should be split
countthe maximum number of result tokens
Returns
a list containing the tokens
NULL if an error occured
VTM_API int vtm_str_split_ex ( const char *  in,
const char *  delim,
char ***  out_tokens,
size_t *  token_count 
)

Splits the given input string by given delimiter.

Parameters
inNUL-terminated input string
delimNUL-terminated delimiter string
[out]out_tokensfilled with array of pointers to tokens
[out]token_countfilled with number of tokens in array
Returns
VTM_OK if the split operation was successful
VTM_E_MALLOC if not enough memory could be allocated
VTM_API char* vtm_str_trim ( char *  in)

Removes whitespaces at begin and end of the input string.

The result is a pointer to same string and does not need to be freed.

Parameters
inthe input string
Returns
pointer to first non-whitespace character
VTM_API char* vtm_str_printf ( const char *  fmt,
  ... 
)

Prints fmt with arguments in returned string.

Parameters
fmtthe format string
Returns
the formatted string
NULL if an error occured, for example if not enough memory could be allocated
VTM_API char* vtm_str_vprintf ( const char *  fmt,
va_list  ap 
)

Prints fmt with arguments in returned string.

Parameters
fmtthe format string
apthe variadic argument list
Returns
the formatted string
NULL if an error occured, for example if not enough memory could be allocated
VTM_API ssize_t vtm_str_index_of ( const char *  in,
char  c,
size_t  len 
)

Searches first occurence of given character.

Parameters
inthe input string
cthe searched character
lenthe length of the input string
Returns
>= 0 when character was found
-1 if not found
-2 when len > SSIZE_MAX
VTM_API ssize_t vtm_str_index_chars ( const char *  in,
size_t  len,
char *  chars,
size_t  char_count,
char *  out_found 
)

Searches first occurence of any of the given characters.

Parameters
inthe input string
lenthe length of the input string
charsarray of searched characters
char_countchar array length
[out]out_foundthe found character
Returns
=> 0 when one of the characters was found
-1 if no character was found
VTM_API ssize_t vtm_str_index_pattern ( const char *  in,
const char *  pattern,
size_t  input_len,
size_t  pattern_len 
)

Searches the first occurence of the given pattern.

Parameters
inthe input string
patternthe search pattern
input_lenthe length of the input string
pattern_lenthe length of the pattern
Returns
>= 0 when pattern was found
-1 if not found
-2 when input_len > SSIZE_MAX
VTM_API bool vtm_str_list_contains ( const char *  in,
const char *  delim,
const char *  search,
bool  nocase 
)

Checks if the list with given delimeter contains search string.

Parameters
inthe input string
delimthe list delimeter
searchthe search patttern
nocasetrue if comparison should be case-insensitive
Returns
true if the list contains the search string
false otherwise
VTM_API size_t vtm_str_pattern_count ( const char *  in,
const char *  pattern 
)

Evaluates how often the given pattern exists in the input string.

Parameters
inthe input string
patternthe search pattern
Returns
the number of pattern occurences
VTM_API bool vtm_str_starts_with ( const char *  in,
const char *  start 
)

Checks if first string begins with the seconds string.

Parameters
theinput string
theprefix
Returns
true if input starts with given prefix
false otherwise