Mir 1.0
Mir application programming interface
String handling routines

Data Structures

struct  mirkl_str_list_t_
 List of strings. More...
 

Typedefs

typedef struct mirkl_str_list_t_ mirkl_str_list_t
 List of strings.
 

Functions

mirkl_error_tmirkl_strlist_create (mirkl_str_list_t **slist, apr_pool_t *pool)
 
void mirkl_strlist_destroy (mirkl_str_list_t *slist)
 
void mirkl_strlist_clear (mirkl_str_list_t *slist)
 
mirkl_error_tmirkl_strlist_addfirst (mirkl_str_list_t *slist, const char *str, apr_pool_t *pool)
 
mirkl_error_tmirkl_strlist_addlast (mirkl_str_list_t *slist, const char *str, apr_pool_t *pool)
 
char * mirkl_strlist_getn (mirkl_str_list_t *slist, int n)
 
mirkl_error_tmirkl_strlist_copy (mirkl_str_list_t *dst, mirkl_str_list_t *src, apr_pool_t *pool)
 
int mirkl_strlist_is_exists (mirkl_str_list_t *slist, const char *str)
 
int mirkl_strlist_nelts (mirkl_str_list_t *slist)
 
mirkl_error_tmirkl_strlist_tokenize (mirkl_str_list_t *slistInp, mirkl_str_list_t *slistOut, const char *seps, apr_pool_t *pool)
 
mirkl_size_t mirkl_str_strlcat (char *dst, const char *src, mirkl_size_t siz)
 appends the NUL-terminated string src to the end of dst. It will append at most (size - strlen(dst) - 1) bytes, NUL-terminating the result. More...
 
mirkl_size_t mirkl_str_strlcpy (char *dst, const char *src, mirkl_size_t siz)
 copies up to (size - 1) characters from the NUL-terminated string src to dst, NUL-terminating the result. More...
 
int mirkl_str_stricmp (const char *s1, const char *s2)
 
int mirkl_str_len (const char *s)
 
mirkl_size_t mirkl_str_utf8_len (const char *s)
 
char * mirkl_str_trim (char *str)
 
mirkl_error_tmirkl_str_to_double (const char *str, double *val)
 
mirkl_error_tmirkl_str_to_integer (const char *str, int *val)
 
mirkl_error_tmirkl_str_to_int64 (const char *str, mirkl_int64_t *val)
 
int mirkl_str_int64_to_base62 (mirkl_int64_t num, int base, char *out, mirkl_size_t len)
 Return string representation of a signed 64-bit integer in the defined base. More...
 
mirkl_error_tmirkl_str_base62_to_int64 (const char *nptr, char **endptr, int base, mirkl_int64_t *val)
 Convert string representing an integer in particular base to a signed 64-bit integer in base 10. More...
 
mirkl_bool_t mirkl_str_is_integer (const char *str)
 Checks whether string represents a valid signed integer. More...
 
mirkl_error_tmirkl_str_escape_parse (char *buf, mirkl_size_t *len, const char *inbuf, mirkl_size_t inlen, int wide_char_string, int use_unicode)
 Search for escape sequences, parse them and substitute with binary representation. More...
 
mirkl_error_tmirkl_str_escape_unparse (char *buf, mirkl_size_t *len, const char *inbuf, mirkl_size_t inlen)
 This function is inverse to mirkl_str_escape_parse. It transforms parsed sequences back to escaped form. More...
 
char * mirkl_str_replace (const char *str, const char *substr, const char *replace)
 Creates a new string as a result of replacement of a substring in the original string. More...
 
char * mirkl_str_replace_all (const char *str, const char *substr, const char *replace)
 Same as mirkl_str_replace but does all possible replacements. More...
 
char * mirkl_str_replace_char (char *str, char find, char replace)
 Replaces all occurrences of a character in a string by another character. More...
 
int mirkl_str_asprintf (char **buf, const char *msg_format,...) __attribute__((format(printf
 Portable asprintf function. More...
 
int int mirkl_str_vasprintf (char **buf, const char *msg_format, va_list arg_buffer)
 Portable vasprintf function. More...
 
int mirkl_str_snprintf (char *buf, mirkl_size_t siz, const char *msg_format,...) __attribute__((format(printf
 Portable snprintf function. More...
 
int char * mirkl_str_pvsprintf (apr_pool_t *pool, const char *msg_format, va_list arg_buffer)
 
char * mirkl_str_psprintf (apr_pool_t *pool, const char *msg_format,...) __attribute__((format(printf
 

Detailed Description

Function Documentation

◆ mirkl_str_asprintf()

int mirkl_str_asprintf ( char **  buf,
const char *  msg_format,
  ... 
)

Portable asprintf function.

Parameters
[out]bufAllocated bufer with string.
Warning
The returned memory must be manually freed!
Returns
Number of bytes printed. On error negative value returned.

◆ mirkl_str_base62_to_int64()

mirkl_error_t * mirkl_str_base62_to_int64 ( const char *  nptr,
char **  endptr,
int  base,
mirkl_int64_t *  val 
)

Convert string representing an integer in particular base to a signed 64-bit integer in base 10.

Parameters
[in]nptrPointer to the string to be converted.
[in,out]endptrIf not NULL this will be set to the first invalid character.
[in]baseOriginal base of the number in the input string. The valid values of the base are between 2 and 62.
[out]valConverted value on the output.
Returns
Returns error if string cannot be converted.
Note
Invalid characters do not lead to an error. The conversion goes until first invalid character.
This function works similar to the well-known strtoll but can handle bases up to 62.
This function is fully compatible with the inverse function mirkl_str_int64_to_base62.

◆ mirkl_str_escape_parse()

mirkl_error_t * mirkl_str_escape_parse ( char *  buf,
mirkl_size_t *  len,
const char *  inbuf,
mirkl_size_t  inlen,
int  wide_char_string,
int  use_unicode 
)

Search for escape sequences, parse them and substitute with binary representation.

Parameters
[io,out]buf Buffer for parsed string. This buffer must be long enough to contain the parsed string.
[in,out]lenOn input this must be the maximal length of the output buffer. On output this variable contains the length of parsed string.
[in]inbufString to be parsed.
[in]inlenLength of the string to be parsed.
[in]wide_char_stringIf not zero, then parsed escape sequences can be represented as wide characters, see https://en.wikipedia.org/wiki/Wide_character
[in]use_unicodeIf not zero, then parsed escape sequences can be represented as Unicode characters. This also requires that wide_char_string is not zero.

◆ mirkl_str_escape_unparse()

mirkl_error_t * mirkl_str_escape_unparse ( char *  buf,
mirkl_size_t *  len,
const char *  inbuf,
mirkl_size_t  inlen 
)

This function is inverse to mirkl_str_escape_parse. It transforms parsed sequences back to escaped form.

Parameters
[io,out]buf Buffer for output string. This buffer must be long enough to contain the output string.
[in,out]lenOn input this must be the maximal length of the output buffer. On output this variable contains the length of the output string.
[in]inbufString to be processed.
[in]inlenLength of the string to be processed.

◆ mirkl_str_int64_to_base62()

int mirkl_str_int64_to_base62 ( mirkl_int64_t  num,
int  base,
char *  out,
mirkl_size_t  len 
)

Return string representation of a signed 64-bit integer in the defined base.

Parameters
[in]numNumber to be converted to a string.
[in]baseConversion must be done for this base. The valid values of the base are between 2 and 62.
[out]outPreallocated buffer for output string. The buffer must be at least 66 bytes long.
[in]lenLength of the buffer.
Returns
Returns number of bytes written to the output buffer.

◆ mirkl_str_is_integer()

mirkl_bool_t mirkl_str_is_integer ( const char *  str)

Checks whether string represents a valid signed integer.

Returns
true if string reptresents an integer, otherwise - false.
Warning
The integer must not necessarily fit into 32 or even 64 bit integer types.

◆ mirkl_str_psprintf()

char * mirkl_str_psprintf ( apr_pool_t *  pool,
const char *  msg_format,
  ... 
)

Portable analog of sprintf function, in which buffer is allocated from an APR pool

Parameters
poolThe pool to allocate out of
msg_formatThe format of the string
...The arguments to use while printing the data
Returns
The new string

◆ mirkl_str_pvsprintf()

int char * mirkl_str_pvsprintf ( apr_pool_t *  pool,
const char *  msg_format,
va_list  arg_buffer 
)

Portable analog of vsprintf function, in which buffer is allocated from an APR pool

Parameters
poolThe pool to allocate out of
msg_formatThe format of the string
arg_bufferThe arguments to use while printing the data
Returns
The new string

◆ mirkl_str_replace()

char * mirkl_str_replace ( const char *  str,
const char *  substr,
const char *  replace 
)

Creates a new string as a result of replacement of a substring in the original string.

Parameters
[in]strOriginal string.
[in]substrSubstring to be replaced.
[in]replaceReplacement string.
Returns
A new string with replacements.
Note
This function does only one first replacement.
Warning
The returned memory must be manually freed!
See also
mirkl_str_replace_all

◆ mirkl_str_replace_all()

char * mirkl_str_replace_all ( const char *  str,
const char *  substr,
const char *  replace 
)

Same as mirkl_str_replace but does all possible replacements.

Warning
The returned memory must be manually freed!

◆ mirkl_str_replace_char()

char * mirkl_str_replace_char ( char *  str,
char  find,
char  replace 
)

Replaces all occurrences of a character in a string by another character.

Parameters
[in]strOriginal string.
[in]findCharacter to find and replace.
[in]replaceNew character.
Returns
Pointer to original string with replaced characters.

◆ mirkl_str_snprintf()

int mirkl_str_snprintf ( char *  buf,
mirkl_size_t  siz,
const char *  msg_format,
  ... 
)

Portable snprintf function.

Parameters
[in,out]bufpreallocated bufer in which the resulting string is printed.
[in]sizsize of preallocated buffer.
Returns
Number of bytes printed. On error negative value returned.

◆ mirkl_str_strlcat()

mirkl_size_t mirkl_str_strlcat ( char *  dst,
const char *  src,
mirkl_size_t  siz 
)

appends the NUL-terminated string src to the end of dst. It will append at most (size - strlen(dst) - 1) bytes, NUL-terminating the result.

Returns
length of the string tried to create.
Note
Truncation occures if the return value is larger than or equal to sizeof(dst).

◆ mirkl_str_strlcpy()

mirkl_size_t mirkl_str_strlcpy ( char *  dst,
const char *  src,
mirkl_size_t  siz 
)

copies up to (size - 1) characters from the NUL-terminated string src to dst, NUL-terminating the result.

Returns
length of the string tried to create.
Note
Truncation occures if the return value is larger than or equal to sizeof(dst).

◆ mirkl_str_vasprintf()

int int mirkl_str_vasprintf ( char **  buf,
const char *  msg_format,
va_list  arg_buffer 
)

Portable vasprintf function.

Parameters
[out]bufAllocated bufer with string.
Warning
The returned memory must be manually freed!
Returns
Number of bytes printed. On error negative value returned.