Mstdlib-1.24.0
|
Functions | |
const char * | M_str_safe (const char *s) |
M_bool | M_str_isempty (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_istrue (const char *s) M_WARN_UNUSED_RESULT |
size_t | M_str_len (const char *s) M_WARN_UNUSED_RESULT |
size_t | M_str_len_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_ispredicate (const char *s, M_chr_predicate_func pred) |
M_bool | M_str_isalnum (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalnumsp (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalpha (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalphasp (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isspace (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isascii (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isgraph (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isprint (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_ishex (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isnum (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_isdec (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_ismoney (const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_ischarset (const char *str, const char *charset) |
M_bool | M_str_isnotcharset (const char *str, const char *charset) |
M_bool | M_str_isstr (const unsigned char *s, size_t len) |
M_bool | M_str_ispredicate_max (const char *s, size_t max, M_chr_predicate_func pred) |
M_bool | M_str_isalnum_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalnumsp_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalpha_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isalphasp_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isspace_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isgraph_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isprint_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_ishex_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isnum_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_isdec_max (const char *s, size_t max) M_WARN_UNUSED_RESULT |
int | M_str_cmpsort (const char *s1, const char *s2) M_WARN_UNUSED_RESULT |
int | M_str_cmpsort_max (const char *s1, const char *s2, size_t max) M_WARN_UNUSED_RESULT |
int | M_str_casecmpsort (const char *s1, const char *s2) M_WARN_UNUSED_RESULT |
int | M_str_casecmpsort_max (const char *s1, const char *s2, size_t max) M_WARN_UNUSED_RESULT |
M_bool | M_str_eq_max (const char *s1, const char *s2, size_t max) |
M_bool | M_str_eq (const char *s1, const char *s2) |
M_bool | M_str_caseeq_max (const char *s1, const char *s2, size_t max) |
M_bool | M_str_caseeq (const char *s1, const char *s2) |
M_bool | M_str_eq_end (const char *s1, const char *s2) |
M_bool | M_str_caseeq_end (const char *s1, const char *s2) |
M_bool | M_str_eq_start (const char *s1, const char *s2) |
M_bool | M_str_caseeq_start (const char *s1, const char *s2) |
M_bool | M_str_pattern_match (const char *pattern, const char *s) M_WARN_UNUSED_RESULT |
M_bool | M_str_case_pattern_match (const char *pattern, const char *s) M_WARN_UNUSED_RESULT |
String Checking and Validation
const char * M_str_safe | ( | const char * | s | ) |
Ensure a NULL will not be used as a string.
[in] | s | NULL-terminated string. |
M_bool M_str_isempty | ( | const char * | s | ) |
Determines if the string is considered empty.
A string is considered empty if it is NULL or has a 0 length.
[in] | s | NULL-terminated string. |
M_bool M_str_istrue | ( | const char * | s | ) |
Check if a string is considered true.
A string is considered true when it equals any of the following (case insensitive):
[in] | s | NULL-terminated string. |
size_t M_str_len | ( | const char * | s | ) |
A wrapper around strlen that treats NULL as a string with length 0.
[in] | s | NULL-terminated string. |
size_t M_str_len_max | ( | const char * | s, |
size_t | max | ||
) |
A wrapper around strlen that treats NULL as a string with length 0, but returns at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes to return. |
M_bool M_str_ispredicate | ( | const char * | s, |
M_chr_predicate_func | pred | ||
) |
Determines if all characters of string s
satisfy predicate pred
.
[in] | s | NULL-terminated string. |
[in] | pred | Predicate to apply to each character. |
M_bool M_str_isalnum | ( | const char * | s | ) |
Check whether each character of a string s are alphanumeric.
[in] | s | NULL-terminated string. |
M_bool M_str_isalnumsp | ( | const char * | s | ) |
Check whether each character of a string s ar alphanumeric or contains spaces.
[in] | s | NULL-terminated string. |
M_bool M_str_isalpha | ( | const char * | s | ) |
Check whether each character of a string s is alpha.
[in] | s | NULL-terminated string. |
M_bool M_str_isalphasp | ( | const char * | s | ) |
Check whether each character of a string s is alpha or contains spaces.
[in] | s | NULL-terminated string. |
M_bool M_str_isspace | ( | const char * | s | ) |
Check whether each character of a string s is a space.
[in] | s | NULL-terminated string. |
M_bool M_str_isascii | ( | const char * | s | ) |
Checks for 7-bit ASCII character.
[in] | s | NULL-terminated string. |
M_bool M_str_isgraph | ( | const char * | s | ) |
Check whether each character of a string s is printable except space.
[in] | s | NULL-terminated string. |
M_bool M_str_isprint | ( | const char * | s | ) |
Check whether each character of a string s is printable.
[in] | s | NULL-terminated string. |
M_bool M_str_ishex | ( | const char * | s | ) |
Check whether each character of a string s is a hexadecimal digit.
[in] | s | NULL-terminated string. |
M_bool M_str_isnum | ( | const char * | s | ) |
Check whether each character of a string s is a decimal digit 0-9.
[in] | s | NULL-terminated string. |
M_bool M_str_isdec | ( | const char * | s | ) |
Check whether each character of a string s is a decimal digit 0-9 or contains a decimal.
[in] | s | NULL-terminated string. |
M_bool M_str_ismoney | ( | const char * | s | ) |
Check whether each character of a string s is a money amount.
Assumes no more than 2 decimal places but does not require 2 decimial digits.
[in] | s | NULL-terminated string. |
M_bool M_str_ischarset | ( | const char * | str, |
const char * | charset | ||
) |
Check whether each character of a string is in the given character set.
[in] | str | string to check (NULL-terminated). |
[in] | charset | list of characters that are allowed in str (NULL-terminated). |
M_bool M_str_isnotcharset | ( | const char * | str, |
const char * | charset | ||
) |
Check whether each character of a string is not in the given character set.
[in] | str | string to check (NULL-terminated). |
[in] | charset | list of characters that are not allowed in str (NULL-terminated). |
M_bool M_str_isstr | ( | const unsigned char * | s, |
size_t | len | ||
) |
Check whether or not the data provided is a string.
This is useful for parsing binary protocols that contain string data as a verification. The length passed in is the size of the buffer, the last byte of the buffer must be a NULL terminator or this function will fail (This means, of course, the string length should be exactly 1 byte less than the provided buffer size). Then the remainder of the buffer will be checked for printable data, otherwise it is not considered a string.
[in] | s | Buffer to see if data is a null-terminated string |
[in] | len | Size of buffer, including NULL terminator |
M_bool M_str_ispredicate_max | ( | const char * | s, |
size_t | max, | ||
M_chr_predicate_func | pred | ||
) |
Determines if the first max
characters of string s
satisfy predicate pred
up to max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Max number of characters to process of s . |
[in] | pred | Predicate to apply to each character. |
M_bool M_str_isalnum_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s are alphanumeric up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isalnumsp_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s ar alphanumeric or contains spaces up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isalpha_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is alpha up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isalphasp_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is alpha or contains spaces up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isspace_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is a space up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isgraph_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is printable except space up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isprint_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is printable up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_ishex_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is a hexadecimal digit up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isnum_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is a decimal digit 0-9 up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
M_bool M_str_isdec_max | ( | const char * | s, |
size_t | max | ||
) |
Check whether each character of a string s is a decimal digit 0-9 or contains a decimal up to at most max bytes.
[in] | s | NULL-terminated string. |
[in] | max | Maximum number of bytes. |
int M_str_cmpsort | ( | const char * | s1, |
const char * | s2 | ||
) |
A wrapper around strcmp that treats NULL as an empty string.
NOTE: this is not a constant-time comparison and thus should ONLY be used for sorting such as within qsort()!
[in] | s1 | NULL-terminated string. |
[in] | s2 | NULL-terminated string. |
int M_str_cmpsort_max | ( | const char * | s1, |
const char * | s2, | ||
size_t | max | ||
) |
A wrapper around strcmp that treats NULL as an empty string, but limited to max characters.
NOTE: this is not a constant-time comparison and thus should ONLY be used for sorting such as within qsort()!
[in] | s1 | NULL-terminated string. |
[in] | s2 | NULL-terminated string. |
[in] | max | Max number of characters to process of s . |
int M_str_casecmpsort | ( | const char * | s1, |
const char * | s2 | ||
) |
A wrapper around strcmp that treats NULL as an empty string and compares case insensitive.
NOTE: this is not a constant-time comparison and thus should ONLY be used for sorting such as within qsort()!
[in] | s1 | NULL-terminated string. |
[in] | s2 | NULL-terminated string. |
int M_str_casecmpsort_max | ( | const char * | s1, |
const char * | s2, | ||
size_t | max | ||
) |
A wrapper around strcmp that treats NULL as an empty string and compares case insensitive, but limited to max characters.
NOTE: this is not a constant-time comparison and thus should ONLY be used for sorting such as within qsort()!
[in] | s1 | NULL-terminated string. |
[in] | s2 | NULL-terminated string. |
[in] | max | Max number of characters to process of s . |
M_bool M_str_eq_max | ( | const char * | s1, |
const char * | s2, | ||
size_t | max | ||
) |
Comparison for string equality.
This implementation is constant-time meaning it should not be vulnerable to timing-based attacks. Limited to first max bytes. NULL and "" are considered equal strings.
s1 will be evaluated to max regardless of the length of s2. s1 should be the input (user) string and s2 the known (internal) string. This order causes any timing information from this function to be the timing of reading s1. The length of s2 cannot be determined using this order. If s1 is the known (internal) string it is possible, though highly unlikely, to determine the length. While the evaluation will be constant time it will always be the time to scan the known string.
[in] | s1 | NULL-terminated string. Should be (user) input. |
[in] | s2 | NULL-terminated string. Should be known (internal) string. |
[in] | max | maximum length to check. |
M_bool M_str_eq | ( | const char * | s1, |
const char * | s2 | ||
) |
Comparison for string equality.
This implementation is constant-time meaning it should not be vulnerable to timing-based attacks. NULL and "" are considered equal strings.
s1 will be evaluated to end regardless of the length of s2. s1 should be the input (user) string and s2 the known (internal) string. This order causes any timing information from this function to be the timing of reading s1. The length of s2 cannot be determined using this order. If s1 is the known (internal) string it is possible though highly unlikely, to determine the length. While the evaluation will be constant time it will always be the time to scan the known string.
[in] | s1 | NULL-terminated string. Should be (user) input. |
[in] | s2 | NULL-terminated string. Should be known (internal) string. |
M_bool M_str_caseeq_max | ( | const char * | s1, |
const char * | s2, | ||
size_t | max | ||
) |
Comparison for string equality in a case-insensitive manner.
This implementation is constant-time meaning it should not be vulnerable to timing-based attacks. Limited to first max bytes. NULL and "" are considered equal strings.
s1 will be evaluated to max regardless of the length of s2. s1 should be the input (user) string and s2 the known (internal) string. This order causes any timing information from this function to be the timing of reading s1. The length of s2 cannot be determined though highly unlikely, to determine the length. While the evaluation will be constant time it will always be the time to scan the known string.
[in] | s1 | NULL-terminated string. |
[in] | s2 | NULL-terminated string. |
[in] | max | maximum length to check. |
M_bool M_str_caseeq | ( | const char * | s1, |
const char * | s2 | ||
) |
Comparison for string equality in a case-insensitive manner.
This implementation is constant-time meaning it should not be vulnerable to timing-based attacks. NULL and "" are considered equal strings.
s1 will be evaluated to end regardless of the length of s2. s1 should be the input (user) string and s2 the known (internal) string. This order causes any timing information from this function to be the timing of reading s1. The length of s2 cannot be determined though highly unlikely, to determine the length. While the evaluation will be constant time it will always be the time to scan the known string.
[in] | s1 | NULL-terminated string. Should be (user) input. |
[in] | s2 | NULL-terminated string. Should be known (internal) string. |
M_bool M_str_eq_end | ( | const char * | s1, |
const char * | s2 | ||
) |
Determine if a string ends with a given string.
The input is slighly different than M_str_eq(). The input reads: Check that s1 ends with s2.
s1 length is never (
[in] | s1 | NULL-terminated string, or non-terminated string that's at least as long as s2. Input string. |
[in] | s2 | NULL-terminated string. Ending string that's being compared to s1. |
M_bool M_str_caseeq_end | ( | const char * | s1, |
const char * | s2 | ||
) |
Determine if a string ends with a given string in a case-insensitive manner.
The input is slighly different than M_str_caseeq(). The input reads: Check that s1 ends with s2.
s1 length is never (
[in] | s1 | NULL-terminated string, or non-terminated string that's at least as long as s2. Input string. |
[in] | s2 | NULL-terminated string. Ending string that's being compared to s1. |
M_bool M_str_eq_start | ( | const char * | s1, |
const char * | s2 | ||
) |
Determine if a string starts with a given string.
The input is slighly different than M_str_eq(). The input reads: Check that s1 starts with s2.
s1 length is never (
[in] | s1 | NULL-terminated string, or non-terminated string that's at least as long as s2. Input string. |
[in] | s2 | NULL-terminated string. Staring string that's being compared to s1. |
M_bool M_str_caseeq_start | ( | const char * | s1, |
const char * | s2 | ||
) |
Determine if a string starts with a given string in a case-insensitive manner.
The input is slightly different than M_str_caseeq(). The input reads: Check that s1 starts with s2.
s1 length is never (see M_str_caseeq()) known because evaluation will always be the length of s2.
[in] | s1 | NULL-terminated string, or non-terminated string that's at least as long as s2. Input string. |
[in] | s2 | NULL-terminated string. Staring string that's being compared to s1. |
M_bool M_str_pattern_match | ( | const char * | pattern, |
const char * | s | ||
) |
Match pattern against string as per 'man 7 glob'.
We don't support newer POSIX functions like named character classes (e.g. [:lower:]), collating symbols, or equivalence class expressions
[in] | pattern | The pattern to match using. |
[in] | s | NULL-terminated string. |
M_bool M_str_case_pattern_match | ( | const char * | pattern, |
const char * | s | ||
) |
Match pattern against string as per 'man 7 glob' case insensitive.
We don't support newer POSIX functions like named character classes (e.g. [:lower:]), collating symbols, or equivalence class expressions
[in] | pattern | The pattern to match using. |
[in] | s | NULL-terminated string. |