Mstdlib-1.24.0
String Manipulation (and Duplication)

Enumerations

enum  M_str_justify_type_t {
  M_STR_JUSTIFY_RIGHT = 0 ,
  M_STR_JUSTIFY_LEFT = 1 ,
  M_STR_JUSTIFY_RIGHT_TRUNC_RIGHT = 2 ,
  M_STR_JUSTIFY_LEFT_TRUNC_RIGHT = 3 ,
  M_STR_JUSTIFY_RIGHT_NOTRUNC = 4 ,
  M_STR_JUSTIFY_LEFT_NOTRUNC = 5 ,
  M_STR_JUSTIFY_TRUNC_RIGHT = 6 ,
  M_STR_JUSTIFY_TRUNC_LEFT = 7 ,
  M_STR_JUSTIFY_CENTER = 8 ,
  M_STR_JUSTIFY_CENTER_TRUNC_RIGHT = 9 ,
  M_STR_JUSTIFY_CENTER_NO_TRUNC = 10 ,
  M_STR_JUSTIFY_END = 11
}
 

Functions

char * M_strdup (const char *s) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_upper (const char *s) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_lower (const char *s) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_title (const char *s) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_trim (const char *s) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_unquote (const char *s, unsigned char quote, unsigned char escape) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_max (const char *s, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_upper_max (const char *s, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_lower_max (const char *s, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_title_max (const char *s, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_trim_max (const char *s, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_unquote_max (const char *s, unsigned char quote, unsigned char escape, size_t max) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_justify (const char *src, M_str_justify_type_t justtype, unsigned char justchar, size_t justlen) M_WARN_UNUSED_RESULT M_MALLOC
 
char * M_strdup_replace_charset (const char *s, const unsigned char *bcs, size_t bcs_len, const char *a)
 
char * M_strdup_replace_str (const char *s, const char *b, const char *a)
 

Detailed Description

String Manipulation (and Duplication) Functions

Enumeration Type Documentation

◆ M_str_justify_type_t

Justify Flags

Enumerator
M_STR_JUSTIFY_RIGHT 

Data is right-justified (padded on left). If src exceeds justification length, it is truncated on the left

M_STR_JUSTIFY_LEFT 

Data is left-justified (padded on right). If src exceeds justification length, it is truncated on the left

M_STR_JUSTIFY_RIGHT_TRUNC_RIGHT 

Data is right-justified (padded on left). If src exceeds justification length, it is truncated on the right

M_STR_JUSTIFY_LEFT_TRUNC_RIGHT 

Data is left-justified (padded on right). If src exceeds justification length, it is truncated on the right

M_STR_JUSTIFY_RIGHT_NOTRUNC 

Data is right-justified (padded on left). If src exceeds justification length, destination is not written, error is returned

M_STR_JUSTIFY_LEFT_NOTRUNC 

Data is left-justified (padded on right). If src exceeds justification length, destination is not written, error is returned

M_STR_JUSTIFY_TRUNC_RIGHT 

Data is truncated on the right if length is exceeded. No padding is performed

M_STR_JUSTIFY_TRUNC_LEFT 

Data is truncated on the left if length is exceeded. No padding is performed

M_STR_JUSTIFY_CENTER 

Data is center-justified (padded on left and right). If src exceeds justification length, it is truncated on the left

M_STR_JUSTIFY_CENTER_TRUNC_RIGHT 

Data is center-justified (padded on left and right). If src exceeds justification length, it is truncated on the right

M_STR_JUSTIFY_CENTER_NO_TRUNC 

Data is center-justified (padded on left and right). If src exceeds justification length, destination is not writtern, error is returned

M_STR_JUSTIFY_END 

Non-used value that marks end of list.

Function Documentation

◆ M_strdup()

char * M_strdup ( const char *  s)

Create a duplicate of the NULL-terminated string s.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated string.
See also
M_free

◆ M_strdup_upper()

char * M_strdup_upper ( const char *  s)

Create a duplicate of the NULL-terminated string s and additionally applies M_str_upper to the new string.

Later s can be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated string.
See also
M_strdup
M_str_upper
M_free

◆ M_strdup_lower()

char * M_strdup_lower ( const char *  s)

Create a duplicate of the NULL-terminated string s and additionally applies M_str_lower to the new string.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated string.
See also
M_strdup
M_str_lower
M_free

◆ M_strdup_title()

char * M_strdup_title ( const char *  s)

Create new string with all characters converted to title case.

Title case is where the first letter of each word is converted to uppercase, and all other letters are converted to lowercase.

Ex: "This Sentence Is In Title Case"

See also
M_strdup_title_max
M_str_title
M_free
Parameters
[in]snull-terminated string to duplicate and convert.
Returns
newly allocated string on success, NULL on failure.

◆ M_strdup_trim()

char * M_strdup_trim ( const char *  s)

Create a duplicate of the NULL-terminated string s and additionally applies M_str_trim to the new string.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated string.
See also
M_strdup
M_str_trim
M_free

◆ M_strdup_unquote()

char * M_strdup_unquote ( const char *  s,
unsigned char  quote,
unsigned char  escape 
)

Create a duplicate of the NULL-terminated string s and additionally applies M_str_unquote to the new string.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string.
[in]quoteQuote character that should be removed.
[in]escapeCharacter that escapes a quote that is within the quoted string.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated string.
See also
M_strdup
M_str_unquote
M_free

◆ M_strdup_max()

char * M_strdup_max ( const char *  s,
size_t  max 
)

Create a duplicate of the NULL-terminated string s, but copy at most max bytes.

If s is longer than max, only max bytes are copied. The returned string will always be NULL-terminated.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string (or up to max bytes of s).
[in]maxMaximum number of bytes to copy from s.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated substring s[0..MAX(max-1,strlen(s))].
See also
M_free

◆ M_strdup_upper_max()

char * M_strdup_upper_max ( const char *  s,
size_t  max 
)

Create a duplicate of the NULL-terminated string s, but copy at most max bytes and additionally applies M_str_lower_max to the new string.

If s is longer than max, only max bytes are copied. The returned string will always be NULL-terminated.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string (or up to max bytes of s).
[in]maxMaximum number of bytes to copy from s.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated substring s[0..MAX(max-1,strlen(s))].
See also
M_strdup_max
M_str_upper_max
M_free

◆ M_strdup_lower_max()

char * M_strdup_lower_max ( const char *  s,
size_t  max 
)

Create a duplicate of the NULL-terminated string s, but copy at most max bytes and additionally applies M_str_lower_max to the new string.

If s is longer than max, only max bytes are copied. The returned string will always be NULL-terminated.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string (or up to max bytes of s).
[in]maxMaximum number of bytes to copy from s.
See also
M_strdup_max
M_str_lower_max
M_free

◆ M_strdup_title_max()

char * M_strdup_title_max ( const char *  s,
size_t  max 
)

Create new string with a given number of characters converted to title case.

Only copies up to max characters from the source string.

Title case is where the first letter of each word is converted to uppercase, and all other letters are converted to lowercase.

Ex: "This Sentence Is In Title Case"

See also
M_strdup_title
M_str_title_max
M_free
Parameters
[in]snull-terminated string to duplicate and convert.
[in]maxmax number of characters to copy from s, may be less if s contains a null character
Returns
newly allocated string on success, NULL on failure.

◆ M_strdup_trim_max()

char * M_strdup_trim_max ( const char *  s,
size_t  max 
)

Create a duplicate of the NULL-terminated string s, but copy at most max bytes and additionally applies M_str_trim_max to the new string.

If s is longer than max, only max bytes are copied. The returned string will always be NULL-terminated.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string (or up to max bytes of s).
[in]maxMaximum number of bytes to copy from s.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated substring s[0..MAX(max-1,strlen(s))].
See also
M_strdup_max
M_str_trim_max
M_free

◆ M_strdup_unquote_max()

char * M_strdup_unquote_max ( const char *  s,
unsigned char  quote,
unsigned char  escape,
size_t  max 
)

Create a duplicate of the NULL-terminated string s, but copy at most max bytes and additionally applies M_str_unquote_max to the new string.

If s is longer than max, only max bytes are copied. The returned string will always be NULL-terminated.

s must be passed to M_free to release the memory space associated with it.

Parameters
[in]sNULL-terminated string (or up to max bytes of s).
[in]quoteQuote character that should be removed.
[in]escapeCharacter that escapes a quote that is within the quoted string.
[in]maxMaximum number of bytes to copy from s.
Returns
NULL when insufficient memory or s is NULL. Otherwise a NULL-terminated substring s[0..MAX(max-1,strlen(s))].
See also
M_strdup_max
M_free

◆ M_strdup_justify()

char * M_strdup_justify ( const char *  src,
M_str_justify_type_t  justtype,
unsigned char  justchar,
size_t  justlen 
)

Justifies the input source as specified by the parameters and writes it to a new duplicate string.

Parameters
[in]srcNull-terminated input string to be justified.
[in]justtypeType of justification to be performed.
[in]justcharCharacter to use as padding/filler for justification. (ignored if M_JUSTIFY_TRUNC_RIGHT or M_JUSTIFY_TRUNC_LEFT)
[in]justlenLength requested for justification (or truncation).
Returns
NULL on error (such as if it would truncate when requested not to, or invalid use). New null-terminated string containing justified output on success.

◆ M_strdup_replace_charset()

char * M_strdup_replace_charset ( const char *  s,
const unsigned char *  bcs,
size_t  bcs_len,
const char *  a 
)

Replace all characters matching a given character set with a string.

Parameters
[in]sNULL-terminated string.
[in]bcsCharacter set.
[in]bcs_lenNumber of characters in the given set.
[in]aReplacement string for every character in the character set.
Returns
NULL terminated string on success, Otherwise NULL.
See also
M_str_replace_chr
M_strdup_replace_str

◆ M_strdup_replace_str()

char * M_strdup_replace_str ( const char *  s,
const char *  b,
const char *  a 
)

Replace a string with another string.

Parameters
[in]sNULL-terminated string.
[in]bNULL-terminated string to replace.
[in]aNULL-terminated string o replace with. b is replaced with a.
Returns
NULL terminated string on success, Otherwise NULL.
See also
M_str_replace_chr
M_strdup_replace_charset