This section contains utilities relating to string manipulation. More...
Modules | |
String Object | |
A String buffer implementation. This implementation allows for dynamically creating string and appending to them in a reasonably efficient matter. | |
Macros | |
#define | ruUtf8Nfc 1 |
Normalizer Mode for NFC normalization for ruUtf8CaseNormalize. More... | |
#define | ruUtf8Nfd 2 |
Normalizer Mode for NFD normalization for ruUtf8CaseNormalize. More... | |
#define | ruUtf8NoCase 0 |
Casemode constant to leave case for ruUtf8CaseNormalize intact. More... | |
#define | ruUtf8Lower 1 |
Casemode constant to lower case text for ruUtf8CaseNormalize. More... | |
#define | ruUtf8Upper 2 |
Casemode constant to lower case text for ruUtf8CaseNormalize. More... | |
Enumerations | |
enum | ruTrimSide { ruTrimBoth = (uint32_t)0 , ruTrimStart = 1 , ruTrimEnd = 2 } |
Functions | |
RUAPI char * | ruUtf8CaseNormalize (const char *instr, int32_t normMode, int32_t caseMode) |
Returns the given string normalized and/or case switched as requested. More... | |
RUAPI alloc_chars | ruStrFromNfd (trans_chars instr) |
Returns the given decomposed string in precomposed form. More... | |
RUAPI alloc_chars | ruStrToNfd (trans_chars instr) |
Returns the given string in decomposed form. More... | |
RUAPI void | ruStrByteReplace (char *string, char search, char replace) |
Replaces any occurrence of search in string with replace. More... | |
RUAPI alloc_chars | ruStrReplace (trans_chars instr, trans_chars search, trans_chars replace) |
Replaces any occurrence of search in instr with replace. More... | |
RUAPI int32_t | ruStrCmp (trans_chars str1, trans_chars str2) |
Returns what libc strcmp would return but in a manner that gracefully handles NULL imputs. More... | |
RUAPI bool | ruStrEquals (trans_chars str1, trans_chars str2) |
Returns true when libc strcmp would return 0 but in a manner that gracefully handles NULL imputs. More... | |
RUAPI bool | ruStrNEquals (trans_chars str1, rusize s1len, trans_chars str2) |
Returns true when str2 is equal to the first len number of bytes in str1 or both str1 and str2 are NULL or if len is NULL. More... | |
RUAPI int32_t | ruStrCaseCmp (trans_chars str1, trans_chars str2) |
Returns what libc strcasecmp would return but in a manner that gracefully handles NULL imputs. More... | |
RUAPI bool | ruStrCaseEquals (trans_chars str1, trans_chars str2) |
Returns true when libc strcasecmp would return 0 but in a manner that gracefully handles NULL imputs. More... | |
RUAPI bool | ruStrStartsWith (trans_chars str, trans_chars prefix, int32_t *code) |
Whether given string starts with given prefix. More... | |
RUAPI bool | ruStrCaseStartsWith (trans_chars str, trans_chars prefix, int32_t *code) |
Whether given string starts with given prefix ignoring case. More... | |
RUAPI bool | ruStrEndsWith (trans_chars str, trans_chars suffix, int32_t *code) |
Whether given string ends with given suffix. More... | |
RUAPI bool | ruStrCaseEndsWith (trans_chars str, trans_chars suffix, int32_t *code) |
Whether given string ends with given suffix ignoring case. More... | |
RUAPI trans_chars | ruStrCaseStrLen (trans_chars haystack, trans_chars needle, rusize len) |
Searches the first instance of lowercase needle in lowercase haystack up to len bytes. Lowercasing is only ASCII compatible. More... | |
RUAPI trans_chars | ruStrStrLen (trans_chars haystack, trans_chars needle, rusize len) |
Searches the first instance of needle in haystack up to len bytes. More... | |
RUAPI trans_chars | ruStrStr (trans_chars haystack, trans_chars needle) |
Searches the first instance of needle in haystack. More... | |
RUAPI trans_chars | ruLastSubStrLen (trans_chars haystack, trans_chars needle, rusize len) |
Searches the last instance of needle in haystack up to len bytes. More... | |
RUAPI trans_chars | ruLastSubStr (trans_chars haystack, trans_chars needle) |
Searches the last instance of needle in haystack. More... | |
RUAPI ruList | ruStrNSplit (trans_chars instr, rusize inlen, trans_chars delim, int32_t maxCnt) |
Split given instr up to inlen bytes with delim into a ruList. More... | |
RUAPI ruList | ruStrSplit (trans_chars instr, trans_chars delim, int32_t maxCnt) |
split given instr with delim into a ruList. More... | |
RUAPI char | ruAsciiCharToLower (char in) |
Returns lowercase representation of given ASCII character. More... | |
RUAPI alloc_chars | ruAsciiToLower (trans_chars instr) |
Returns a lowercase copy of given ASCII string. More... | |
RUAPI alloc_chars | ruAsciiNToLower (trans_chars instr, rusize len) |
Returns a lowercase copy of len bytes of given ASCII string. More... | |
RUAPI char | ruAsciiCharToUpper (char in) |
Returns uppercase representation of given ASCII character. More... | |
RUAPI alloc_chars | ruAsciiToUpper (trans_chars instr) |
Returns a uppercase copy of given ASCII string. More... | |
RUAPI alloc_chars | ruAsciiNToUpper (trans_chars instr, rusize len) |
Returns a uppercase copy of len bytes of given ASCII string. More... | |
RUAPI alloc_chars | ruUtf8ToLower (trans_chars instr) |
Returns a lowercase copy of given UTF8 string. More... | |
RUAPI alloc_chars | ruUtf8ToUpper (trans_chars instr) |
Returns a uppercase copy of given UTF8 string. More... | |
RUAPI alloc_chars | ruStrFromNUtf16 (trans_uni unistr, int32_t bytelen) |
Converts given UTF16 wide character sequence to UTF8. More... | |
RUAPI alloc_chars | ruStrFromUtf16 (trans_uni unistr) |
Converts given UTF16 wide character sequence to UTF8. More... | |
RUAPI alloc_uni | ruStrNToUtf16 (trans_chars str, int32_t bytelen) |
Converts given UTF8 string to UTF16 as it is used on Windows. More... | |
RUAPI alloc_uni | ruStrToUtf16 (trans_chars str) |
Converts given UTF8 string to UTF16 as it is used on Windows. More... | |
RUAPI char * | ruStrDup (const char *str) |
Returns a copy of given string. More... | |
RUAPI rusize | ruStrLen (trans_chars str) |
behaves like strlen but returns 0 if NULL is passed in More... | |
RUAPI char * | ruStrNDup (const char *str, rusize len) |
Returns a copy of len bytes of given string. More... | |
RUAPI char * | ruDupvPrintf (const char *format, va_list arglist) |
Returns an allocated string from given vprintf call. More... | |
RUAPI char * | ruDupPrintf (const char *format,...) |
Returns an allocated string from given printf call. More... | |
RUAPI bool | ruIsInt64 (trans_chars str) |
Returns true if given string contains a valid 64 bit integer. More... | |
RUAPI bool | ruIsBool (trans_chars str, bool *val) |
Returns true if given string contains a valid boolean. More... | |
RUAPI int32_t | ruStrParseBool (trans_chars str, perm_chars *endptr, bool *out) |
Parses boolean value out of given string. More... | |
RUAPI int32_t | ruStrParseInt64 (trans_chars str, perm_chars *endptr, uint32_t base, int64_t *num) |
RUAPI int64_t | ruStrToInt64 (trans_chars str) |
Like ruStrParseInt64 but ignores overflow and trailing garbage. More... | |
RUAPI int32_t | ruStrParseLong (trans_chars str, perm_chars *endptr, uint32_t base, long *num) |
RUAPI long | ruStrToLong (trans_chars str) |
Like ruStrParseLong but ignores overflow and trailing garbage. More... | |
RUAPI int32_t | ruStrParseInt (trans_chars str, perm_chars *endptr, uint32_t base, int32_t *num) |
RUAPI int32_t | ruStrToInt (trans_chars str) |
Like ruStrParseInt but ignores overflow and trailing garbage. More... | |
RUAPI bool | ruStrHasChar (trans_chars haystack, char needle) |
RUAPI perm_chars | ruStrStrip (perm_chars instr, trans_chars unwanted, alloc_chars *newstr) |
Removes unwanted characters from instr. More... | |
RUAPI perm_chars | ruStrTrim (perm_chars instr, trans_chars unwanted, enum ruTrimSide ends, alloc_chars *newstr) |
Checks given string for leading / trailing unwanted characters and returns trimmed copy if needed. More... | |
RUAPI trans_chars | ruStrTrimBounds (trans_chars inStart, rusize inLen, rusize *outLen) |
Returns the white space trimmed bounds of given string without modifying it. More... | |
RUAPI bool | ruStrFindKeyVal (trans_chars inStart, rusize inLen, trans_chars delim, trans_chars *keyStart, rusize *keyLen, trans_chars *valStart, rusize *valLen) |
Parses whitespace trimmed key / value regions based on delim out of given input string. More... | |
RUAPI bool | ruStrEmpty (trans_chars str) |
Checks whether given string has any content other than whitespace. More... | |
This section contains utilities relating to string manipulation.
#define ruUtf8Lower 1 |
Casemode constant to lower case text for ruUtf8CaseNormalize.
#define ruUtf8Nfc 1 |
Normalizer Mode for NFC normalization for ruUtf8CaseNormalize.
#define ruUtf8Nfd 2 |
Normalizer Mode for NFD normalization for ruUtf8CaseNormalize.
#define ruUtf8NoCase 0 |
Casemode constant to leave case for ruUtf8CaseNormalize intact.
#define ruUtf8Upper 2 |
Casemode constant to lower case text for ruUtf8CaseNormalize.
enum ruTrimSide |
Constants used by ruStrTrim to indicate the trimming sides.
RUAPI char ruAsciiCharToLower | ( | char | in | ) |
Returns lowercase representation of given ASCII character.
in | Character to lowercase. |
RUAPI char ruAsciiCharToUpper | ( | char | in | ) |
Returns uppercase representation of given ASCII character.
in | Character to lowercase. |
RUAPI alloc_chars ruAsciiNToLower | ( | trans_chars | instr, |
rusize | len | ||
) |
Returns a lowercase copy of len bytes of given ASCII string.
instr | String to lowercase. |
len | The number of bytes to consider |
RUAPI alloc_chars ruAsciiNToUpper | ( | trans_chars | instr, |
rusize | len | ||
) |
Returns a uppercase copy of len bytes of given ASCII string.
instr | String to uppercase. |
len | The number of bytes to consider |
RUAPI alloc_chars ruAsciiToLower | ( | trans_chars | instr | ) |
Returns a lowercase copy of given ASCII string.
instr | String to lowercase. |
RUAPI alloc_chars ruAsciiToUpper | ( | trans_chars | instr | ) |
Returns a uppercase copy of given ASCII string.
instr | String to uppercase. |
RUAPI char* ruDupPrintf | ( | const char * | format, |
... | |||
) |
Returns an allocated string from given printf call.
format | Printf style format string |
... | Remaining arguments for the format string. |
RUAPI char* ruDupvPrintf | ( | const char * | format, |
va_list | arglist | ||
) |
Returns an allocated string from given vprintf call.
format | Printf style format string |
arglist | a va_start initialized argument list |
RUAPI bool ruIsBool | ( | trans_chars | str, |
bool * | val | ||
) |
Returns true if given string contains a valid boolean.
Valid booleans are case insensitive versions of true and false and any number that evaluates to 0 or 1. Evaluating to numbers other than 0 or 1 does not qualify as a valid boolean.
str | String to parse |
val | Where the result will be stored on success. Value is unspecified on error. |
RUAPI bool ruIsInt64 | ( | trans_chars | str | ) |
Returns true if given string contains a valid 64 bit integer.
str | String to parse |
RUAPI trans_chars ruLastSubStr | ( | trans_chars | haystack, |
trans_chars | needle | ||
) |
Searches the last instance of needle in haystack.
haystack | String to search needle in. |
needle | String to find in haystack. |
RUAPI trans_chars ruLastSubStrLen | ( | trans_chars | haystack, |
trans_chars | needle, | ||
rusize | len | ||
) |
Searches the last instance of needle in haystack up to len bytes.
haystack | String to search needle in. |
needle | String to find in haystack. |
len | Maximum number of bytes in haystack to consider. |
RUAPI void ruStrByteReplace | ( | char * | string, |
char | search, | ||
char | replace | ||
) |
Replaces any occurrence of search in string with replace.
This function works byte level not character level. NOTE: Calling this function with strings on the stack will segfault.
string | String to process |
search | Character to replace |
replace | Character to replace search with |
RUAPI int32_t ruStrCaseCmp | ( | trans_chars | str1, |
trans_chars | str2 | ||
) |
Returns what libc strcasecmp would return but in a manner that gracefully handles NULL imputs.
str1 | The first string to check. |
str2 | The second string to compare to the first. |
RUAPI bool ruStrCaseEndsWith | ( | trans_chars | str, |
trans_chars | suffix, | ||
int32_t * | code | ||
) |
Whether given string ends with given suffix ignoring case.
str | String to check. |
suffix | Suffix to test for. |
code | (Optional) Stores RUE_OK on success or regify error code. |
RUAPI bool ruStrCaseEquals | ( | trans_chars | str1, |
trans_chars | str2 | ||
) |
Returns true when libc strcasecmp would return 0 but in a manner that gracefully handles NULL imputs.
str1 | The first string to check. |
str2 | The second string to compare to the first. |
RUAPI bool ruStrCaseStartsWith | ( | trans_chars | str, |
trans_chars | prefix, | ||
int32_t * | code | ||
) |
Whether given string starts with given prefix ignoring case.
str | String to check. |
prefix | Prefix to test for. |
code | (Optional) Stores RUE_OK on success or regify error code. |
RUAPI trans_chars ruStrCaseStrLen | ( | trans_chars | haystack, |
trans_chars | needle, | ||
rusize | len | ||
) |
Searches the first instance of lowercase needle in lowercase haystack up to len bytes. Lowercasing is only ASCII compatible.
haystack | String to search needle in. |
needle | String to find in haystack. |
len | Maximum number of bytes in haystack to consider. |
RUAPI int32_t ruStrCmp | ( | trans_chars | str1, |
trans_chars | str2 | ||
) |
Returns what libc strcmp would return but in a manner that gracefully handles NULL imputs.
str1 | The first string to check. |
str2 | The second string to compare to the first. |
RUAPI char* ruStrDup | ( | const char * | str | ) |
Returns a copy of given string.
str | String to copy |
RUAPI bool ruStrEmpty | ( | trans_chars | str | ) |
Checks whether given string has any content other than whitespace.
str | String to inspect |
RUAPI bool ruStrEndsWith | ( | trans_chars | str, |
trans_chars | suffix, | ||
int32_t * | code | ||
) |
Whether given string ends with given suffix.
str | String to check. |
suffix | Suffix to test for. |
code | (Optional) Stores RUE_OK on success or regify error code. |
RUAPI bool ruStrEquals | ( | trans_chars | str1, |
trans_chars | str2 | ||
) |
Returns true when libc strcmp would return 0 but in a manner that gracefully handles NULL imputs.
str1 | The first string to check. |
str2 | The second string to compare to the first. |
RUAPI bool ruStrFindKeyVal | ( | trans_chars | inStart, |
rusize | inLen, | ||
trans_chars | delim, | ||
trans_chars * | keyStart, | ||
rusize * | keyLen, | ||
trans_chars * | valStart, | ||
rusize * | valLen | ||
) |
Parses whitespace trimmed key / value regions based on delim out of given input string.
inStart | Start of the string to parse |
inLen | Number of bytes to evaluate or RU_SIZE_AUTO. |
delim | Delimiter sequence to split key / value on |
keyStart | Optional, where the start of the key region will be stored |
keyLen | Optional, where the length of the key region will be stored |
valStart | Optional, where the start of the value region will be stored |
valLen | Optional, where the length of the value region will be stored |
RUAPI alloc_chars ruStrFromNfd | ( | trans_chars | instr | ) |
Returns the given decomposed string in precomposed form.
instr | Decomposed UTF8 string. |
RUAPI alloc_chars ruStrFromNUtf16 | ( | trans_uni | unistr, |
int32_t | bytelen | ||
) |
Converts given UTF16 wide character sequence to UTF8.
unistr | UTF16 string to convert. |
bytelen | Length of unistr without terminating bytes or -1 to detect length |
RUAPI alloc_chars ruStrFromUtf16 | ( | trans_uni | unistr | ) |
Converts given UTF16 wide character sequence to UTF8.
unistr | UTF16 string to convert. |
RUAPI bool ruStrHasChar | ( | trans_chars | haystack, |
char | needle | ||
) |
Returns true if given haystack contains needle character
haystack | string to search for needle |
needle | character to search in haystack |
RUAPI rusize ruStrLen | ( | trans_chars | str | ) |
behaves like strlen but returns 0 if NULL is passed in
str | string to get length of |
RUAPI char* ruStrNDup | ( | const char * | str, |
rusize | len | ||
) |
Returns a copy of len bytes of given string.
str | String to copy |
len | Number of bytes to consider. |
RUAPI bool ruStrNEquals | ( | trans_chars | str1, |
rusize | s1len, | ||
trans_chars | str2 | ||
) |
Returns true when str2 is equal to the first len number of bytes in str1 or both str1 and str2 are NULL or if len is NULL.
str1 | The first string to check. |
s1len | Number of bytes in str1 to consider |
str2 | The second string to compare to the first. |
RUAPI ruList ruStrNSplit | ( | trans_chars | instr, |
rusize | inlen, | ||
trans_chars | delim, | ||
int32_t | maxCnt | ||
) |
Split given instr up to inlen bytes with delim into a ruList.
instr | String to split. |
inlen | Optional length delimiter. Use RU_SIZE_AUTO to omit. |
delim | Delimiter to split string on. |
maxCnt | Maximum number of pieces to return or 0 for no limit. The remainder will be unsplit in the last piece. |
RUAPI alloc_uni ruStrNToUtf16 | ( | trans_chars | str, |
int32_t | bytelen | ||
) |
Converts given UTF8 string to UTF16 as it is used on Windows.
str | UTF8 string to convert |
bytelen | Length of str without terminating byte or -1 to detect length. |
RUAPI int32_t ruStrParseBool | ( | trans_chars | str, |
perm_chars * | endptr, | ||
bool * | out | ||
) |
Parses boolean value out of given string.
Leading and trailing whitespace is ignored. Valid booleans are case insensitive versions of true and false and any number that evaluates to 0 or 1. Evaluating to numbers other than 0 or 1 does not qualify as a valid boolean.
str | String to parse |
endptr | (Optional) Points to the first character that did not parse properly |
out | Where the result will be stored on success. Value is unspecified on error. |
RUAPI int32_t ruStrParseInt | ( | trans_chars | str, |
perm_chars * | endptr, | ||
uint32_t | base, | ||
int32_t * | num | ||
) |
Parses the number out of the given string in given base assuming and ignoring comma thousand separators. The decimal point is a period.
str | String to parse. Leading white space will be skipped. |
endptr | (Optional) Points to the first character that did not parse properly |
base | a number between 2 and 36 or 0 for detecting hex with prefix 0x, octal with prefix 0 and else assuming decimal. |
num | Where the number result will be stored or 0 on error. |
RUAPI int32_t ruStrParseInt64 | ( | trans_chars | str, |
perm_chars * | endptr, | ||
uint32_t | base, | ||
int64_t * | num | ||
) |
Parses the number out of the given string in given base assuming and ignoring comma thousand separators. The decimal point is a period.
str | String to parse. Leading white space will be skipped. |
endptr | (Optional) Points to the first character that did not parse properly |
base | a number between 2 and 36 or 0 for detecting hex with prefix 0x, octal with prefix 0 and else assuming decimal. |
num | Where the number result will be stored or 0 on error. |
RUAPI int32_t ruStrParseLong | ( | trans_chars | str, |
perm_chars * | endptr, | ||
uint32_t | base, | ||
long * | num | ||
) |
Parses the number out of the given string in given base assuming and ignoring comma thousand separators. The decimal point is a period.
str | String to parse. Leading white space will be skipped. |
endptr | (Optional) Points to the first character that did not parse properly |
base | a number between 2 and 36 or 0 for detecting hex with prefix 0x, octal with prefix 0 and else assuming decimal. |
num | Where the number result will be stored or 0 on error. |
RUAPI alloc_chars ruStrReplace | ( | trans_chars | instr, |
trans_chars | search, | ||
trans_chars | replace | ||
) |
Replaces any occurrence of search in instr with replace.
instr | String to process |
search | String to replace |
replace | String to replace search with |
RUAPI ruList ruStrSplit | ( | trans_chars | instr, |
trans_chars | delim, | ||
int32_t | maxCnt | ||
) |
split given instr with delim into a ruList.
instr | String to split. |
delim | Delimiter to split string on. |
maxCnt | Maximum number of pieces to return or 0 for no limit. The remainder will be unsplit in the last piece. |
RUAPI bool ruStrStartsWith | ( | trans_chars | str, |
trans_chars | prefix, | ||
int32_t * | code | ||
) |
Whether given string starts with given prefix.
str | String to check. |
prefix | Prefix to test for. |
code | (Optional) Stores RUE_OK on success or regify error code. |
RUAPI trans_chars ruStrStr | ( | trans_chars | haystack, |
trans_chars | needle | ||
) |
Searches the first instance of needle in haystack.
haystack | String to search needle in. |
needle | String to find in haystack. |
RUAPI perm_chars ruStrStrip | ( | perm_chars | instr, |
trans_chars | unwanted, | ||
alloc_chars * | newstr | ||
) |
Removes unwanted characters from instr.
instr | Input string to remove unwanted characters from. |
unwanted | Characters to remove or NULL for white space. |
newstr | Where a potential new copy of the given string will be stored. Caller must free. |
RUAPI trans_chars ruStrStrLen | ( | trans_chars | haystack, |
trans_chars | needle, | ||
rusize | len | ||
) |
Searches the first instance of needle in haystack up to len bytes.
haystack | String to search needle in. |
needle | String to find in haystack. |
len | Maximum number of bytes in haystack to consider. |
RUAPI int32_t ruStrToInt | ( | trans_chars | str | ) |
Like ruStrParseInt but ignores overflow and trailing garbage.
str | String to contain numerals to parse |
RUAPI int64_t ruStrToInt64 | ( | trans_chars | str | ) |
Like ruStrParseInt64 but ignores overflow and trailing garbage.
str | String to contain numerals to parse |
RUAPI long ruStrToLong | ( | trans_chars | str | ) |
Like ruStrParseLong but ignores overflow and trailing garbage.
str | String to contain numerals to parse |
RUAPI alloc_chars ruStrToNfd | ( | trans_chars | instr | ) |
Returns the given string in decomposed form.
instr | Standard precomposed UTF8 string |
RUAPI alloc_uni ruStrToUtf16 | ( | trans_chars | str | ) |
Converts given UTF8 string to UTF16 as it is used on Windows.
str | UTF8 string to convert |
RUAPI perm_chars ruStrTrim | ( | perm_chars | instr, |
trans_chars | unwanted, | ||
enum ruTrimSide | ends, | ||
alloc_chars * | newstr | ||
) |
Checks given string for leading / trailing unwanted characters and returns trimmed copy if needed.
instr | String to check for trimming |
unwanted | String containing all unwanted character bytes or NULL to trim whitespace. |
ends | Indicates which sides to trim |
newstr | Optional. Where the new string will be stored if it was created. If no trimming took place this will be NULL. This string should be freed by the caller. |
Example:
RUAPI trans_chars ruStrTrimBounds | ( | trans_chars | inStart, |
rusize | inLen, | ||
rusize * | outLen | ||
) |
Returns the white space trimmed bounds of given string without modifying it.
inStart | Start address of string to examine |
inLen | Number of bytes to examine or RU_SIZE_AUTO |
outLen | Optional, where the length of the returned start address will be stored. |
RUAPI char* ruUtf8CaseNormalize | ( | const char * | instr, |
int32_t | normMode, | ||
int32_t | caseMode | ||
) |
Returns the given string normalized and/or case switched as requested.
instr | The string to convert. |
normMode | Normalization mode of ruUtf8Nfc, ruUtf8Nfd or 0 for untouched. |
caseMode | Case toggling mode of ruUtf8Lower, ruUtf8Upper or ruUtf8NoCase for untouched. |
RUAPI alloc_chars ruUtf8ToLower | ( | trans_chars | instr | ) |
Returns a lowercase copy of given UTF8 string.
instr | String to lowercase. |
RUAPI alloc_chars ruUtf8ToUpper | ( | trans_chars | instr | ) |
Returns a uppercase copy of given UTF8 string.
instr | String to uppercase. |