Mstdlib-1.24.0
String Searching

Functions

char * M_str_chr (const char *s, char c) M_WARN_UNUSED_RESULT
 
char * M_str_rchr (const char *s, char c) M_WARN_UNUSED_RESULT
 
char * M_str_find_first_from_charset (const char *str, const char *charset)
 
char * M_str_find_first_not_from_charset (const char *str, const char *charset)
 
char * M_str_str (const char *haystack, const char *needle) M_WARN_UNUSED_RESULT
 
char * M_str_casestr (const char *haystack, const char *needle) M_WARN_UNUSED_RESULT
 
ssize_t M_str_casestr_pos (const char *haystack, const char *needle) M_WARN_UNUSED_RESULT
 

Detailed Description

String Searching

Function Documentation

◆ M_str_chr()

char * M_str_chr ( const char *  s,
char  c 
)

Find the first occurrence of c in s.

See also
M_str_rchr
M_str_str
M_str_find_first_from_charset
M_str_find_first_not_from_charset
Parameters
[in]sNULL-terminated string.
[in]cCharacter to search for.
Returns
NULL if s is NULL or c is not found. Otherwise a pointer to the first occurrence of c in s.

◆ M_str_rchr()

char * M_str_rchr ( const char *  s,
char  c 
)

Find the last occurrence of c in s.

See also
M_str_chr
Parameters
[in]sNULL-terminated string.
[in]cCharacter to search for.
Returns
NULL if s is NULL or c is not found. Otherwise a pointer to the last occurrence of c in s.

◆ M_str_find_first_from_charset()

char * M_str_find_first_from_charset ( const char *  str,
const char *  charset 
)

Find the first occurence in str of any character in charset.

This is identical to C standard function strpbrk(), except that it treats NULL pointers as empty strings instead of segfaulting.

See also
M_str_find_first_not_from_charset
M_str_chr
M_str_str
Parameters
[in]strstring to search in (stored as NULL-terminated C string).
[in]charsetlist of chars to search for (stored as NULL-terminated C string).
Returns
pointer to first matching character from charset in str, or NULL if no matches found

◆ M_str_find_first_not_from_charset()

char * M_str_find_first_not_from_charset ( const char *  str,
const char *  charset 
)

Find the first occurence in str of any character that's not in charset.

See also
M_str_find_first_from_charset
M_str_chr
M_str_str
Parameters
[in]strstring to search in (stored as NULL-terminated C string).
[in]charsetlist of chars to skip (stored as NULL-terminated C string).
Returns
pointer to first char in str that's not in charset, or NULL if no matches found

◆ M_str_str()

char * M_str_str ( const char *  haystack,
const char *  needle 
)

A wrapper around strstr that treats NULL as the empty string.

See also
M_str_chr
M_str_find_first_from_charset
M_str_find_first_not_from_charset
Parameters
[in]haystackString to search.
[in]needleString to search for in haystack.
Returns
Pointer to the first occurrence of needle in haystack; otherwise NULL

◆ M_str_casestr()

char * M_str_casestr ( const char *  haystack,
const char *  needle 
)

A wrapper around strstr that ignores case and treats NULL as the empty string.

Parameters
[in]haystackString to search.
[in]needleString to search for in haystack.
Returns
Pointer to the first occurrence of needle in haystack; otherwise NULL

◆ M_str_casestr_pos()

ssize_t M_str_casestr_pos ( const char *  haystack,
const char *  needle 
)

A wrapper around strstr that ignores case and treats NULL as the empty string.

Parameters
[in]haystackString to search.
[in]needleString to search for in haystack.
Returns
Integer index to the first occurrence of needle in haystack; otherwise -1 if needle is not a substring of haystack