A collection of string utils, such as case-insensitive comparison and StartsWith/EndsWith. More...
#include "donner/base/StringUtils.h"
Static Public Member Functions | |
| template<StringLike T, StringLike U> | |
| static bool | EqualsLowercase (const T &lhs, const U &lowercaseRhs) |
| Compare two strings with case-insensitive comparison, fast-path assuming that one of the strings is all-lowercase. | |
| template<StringComparison Comparison = StringComparison::Default, StringLike T, StringLike U> | |
| static bool | Equals (const T &lhs, const U &rhs) |
| Returns true if two strings are equal, optionally with a case-insensitive comparison. | |
| template<StringComparison Comparison = StringComparison::Default, StringLike T, StringLike U> | |
| static bool | StartsWith (const T &str, const U &otherStr) |
Returns true if str starts with otherStr. | |
| template<StringComparison Comparison = StringComparison::Default, StringLike T, StringLike U> | |
| static bool | EndsWith (const T &str, const U &otherStr) |
Returns true if str ends with otherStr. | |
| template<StringComparison Comparison = StringComparison::Default, StringLike T, StringLike U> | |
| static bool | Contains (const T &str, const U &otherStr) |
Returns true if str contains otherStr. | |
| template<StringComparison Comparison = StringComparison::Default, StringLike T, StringLike U> | |
| static size_t | Find (const T &str, const U &otherStr) |
Returns the position of otherStr within str, or npos if not found. | |
| template<StringLike T> | |
| static std::vector< std::string_view > | Split (const T &str, char ch=' ') |
| Splits a string by a given character, returning the non-empty pieces as std::string_views. | |
| template<StringLike T> | |
| static std::vector< std::string_view > | SplitAsciiWhitespace (const T &str) |
| Split at ASCII whitespace: space, tab, line feed, form feed and carriage return (not vertical tab, which IsAsciiWhitespace includes). | |
| template<StringLike T> | |
| static std::string | ToLowerAscii (const T &str) |
Returns a copy of str with ASCII A-Z mapped to a-z and every other byte unchanged. | |
| static constexpr char | ToLowerAscii (char ch) |
Returns ch with ASCII A-Z mapped to a-z; every other byte is returned unchanged, whatever the process C locale. | |
| static constexpr bool | IsAsciiWhitespace (char ch) |
| Returns true for the bytes std::isspace accepts in the "C" locale: space, tab, line feed, vertical tab, form feed and carriage return. | |
| static constexpr bool | IsAsciiAlnum (char ch) |
| Returns true for ASCII letters and digits (A-Z, a-z, 0-9), the bytes std::isalnum accepts in the "C" locale. | |
| static constexpr bool | IsAsciiAlpha (char ch) |
| Returns true for ASCII letters (A-Z, a-z), the bytes std::isalpha accepts in the "C" locale. | |
| static constexpr bool | IsAsciiDigit (char ch) |
| Returns true for ASCII digits (0-9), the bytes std::isdigit accepts. | |
| template<StringLike T> | |
| static std::string_view | TrimWhitespace (const T &str) |
| Trims leading and trailing whitespace from a string, returning a view of the trimmed string. | |
A collection of string utils, such as case-insensitive comparison and StartsWith/EndsWith.
|
inlinestatic |
Returns true if str contains otherStr.
| str | The string to search within. |
| otherStr | The substring to search for. |
| Comparison | The comparison type to use, defaults to StringComparison::Default. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
str contains otherStr.
|
inlinestatic |
Returns true if str ends with otherStr.
| str | The string to check for a suffix. |
| otherStr | The suffix to check for. |
| Comparison | The comparison type to use, defaults to StringComparison::Default. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
str ends with otherStr.
|
inlinestatic |
Returns true if two strings are equal, optionally with a case-insensitive comparison.
| lhs | The first string to compare. |
| rhs | The second string to compare. |
| Comparison | The comparison type to use, defaults to StringComparison::Default. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
|
inlinestatic |
Compare two strings with case-insensitive comparison, fast-path assuming that one of the strings is all-lowercase.
| lhs | The first string to compare, can be any case. |
| lowercaseRhs | string to compare to, must be lowercase. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
lowercaseRhs is equal to the lhs, ignoring the case of the lhs.
|
inlinestatic |
Returns the position of otherStr within str, or npos if not found.
| str | The string to search within. |
| otherStr | The substring to find. |
| Comparison | The comparison type to use, defaults to StringComparison::Default. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
|
inlinestaticconstexpr |
Returns true for ASCII letters and digits (A-Z, a-z, 0-9), the bytes std::isalnum accepts in the "C" locale.
Unlike std::isalnum, bytes above 0x7F are never letters, whatever the process locale, and any char value is a valid argument.
| ch | The character to classify. |
|
inlinestaticconstexpr |
Returns true for ASCII letters (A-Z, a-z), the bytes std::isalpha accepts in the "C" locale.
Bytes above 0x7F are never letters, whatever the process locale.
| ch | The character to classify. |
|
inlinestaticconstexpr |
Returns true for ASCII digits (0-9), the bytes std::isdigit accepts.
| ch | The character to classify. |
|
inlinestaticconstexpr |
Returns true for the bytes std::isspace accepts in the "C" locale: space, tab, line feed, vertical tab, form feed and carriage return.
Unlike std::isspace, bytes above 0x7F are never whitespace, whatever the process locale.
This set includes vertical tab, unlike the WHATWG ASCII whitespace that SplitAsciiWhitespace splits on. Grammars with their own whitespace set, such as CSS or XML, need their own check.
| ch | The character to classify. |
|
inlinestatic |
Splits a string by a given character, returning the non-empty pieces as std::string_views.
Empty pieces, from leading, trailing, or adjacent separators, are omitted. The views alias str, so str must outlive them.
| T | The string type to split, must be StringLike (have size() and data() methods). |
| str | The string to split. |
| ch | The character to split by. |
str.
|
inlinestatic |
Split at ASCII whitespace: space, tab, line feed, form feed and carriage return (not vertical tab, which IsAsciiWhitespace includes).
Empty tokens are omitted and the returned views alias the input.
| str | String to split, which must outlive the returned views. |
|
inlinestatic |
Returns true if str starts with otherStr.
| str | The string to check for a prefix. |
| otherStr | The prefix to check for. |
| Comparison | The comparison type to use, defaults to StringComparison::Default. |
| T | The type of the first string, must be StringLike (have size() and data()
methods).
@tparam U The type of the second string, must be \c StringLike (have size() and data() methods). |
str starts with otherStr.
|
inlinestaticconstexpr |
Returns ch with ASCII A-Z mapped to a-z; every other byte is returned unchanged, whatever the process C locale.
| ch | The character to lowercase. |
|
inlinestatic |
Returns a copy of str with ASCII A-Z mapped to a-z and every other byte unchanged.
Unlike std::tolower, the result does not depend on the process C locale, so it is safe for lookup keys that must compare equal across locales and for UTF-8 text.
| str | The string to lowercase. |
| T | The type of the string, must be StringLike (have size() and data() methods). |
|
inlinestatic |
Trims leading and trailing whitespace from a string, returning a view of the trimmed string.
The returned view aliases str, so str must outlive it.
| str | The string to trim. |
| T | The type of the string, must be StringLike (have size() and data() methods). |