|
|
ASCII only: unlike <cctype>, they ignore the locale and accept any char.
|
| constexpr bool | isSpace (char c) noexcept |
| |
| constexpr bool | isDigit (char c) noexcept |
| |
| constexpr bool | isUpper (char c) noexcept |
| |
| constexpr bool | isLower (char c) noexcept |
| |
| constexpr bool | isAlpha (char c) noexcept |
| |
| constexpr bool | isAlnum (char c) noexcept |
| |
| constexpr bool | isHexDigit (char c) noexcept |
| |
| constexpr char | toLower (char c) noexcept |
| |
| constexpr char | toUpper (char c) noexcept |
| |
|
The IgnoreCase variants ignore the case of ASCII letters.
|
| constexpr bool | contains (std::string_view str, std::string_view needle) noexcept |
| |
| constexpr bool | contains (std::string_view str, char c) noexcept |
| |
| constexpr bool | equalsIgnoreCase (std::string_view lhs, std::string_view rhs) noexcept |
| |
| constexpr bool | startsWithIgnoreCase (std::string_view str, std::string_view prefix) noexcept |
| |
| constexpr bool | endsWithIgnoreCase (std::string_view str, std::string_view suffix) noexcept |
| |
| constexpr std::size_t | findIgnoreCase (std::string_view str, std::string_view needle, std::size_t from=0) noexcept |
| | Position of the first needle at or after from, or std::string_view::npos.
|
| |
| constexpr bool | containsIgnoreCase (std::string_view str, std::string_view needle) noexcept |
| |
| constexpr int | compareIgnoreCase (std::string_view lhs, std::string_view rhs) noexcept |
| | Three-way comparison like strcmp: negative, zero or positive.
|
| |
|
| template<typename T > |
| std::optional< T > | parseNumber (std::string_view text, int base=10) noexcept |
| | Parses text as a number, or returns std::nullopt if it is not entirely one.
|
| |
| constexpr std::optional< bool > | parseBool (std::string_view text) noexcept |
| | Parses true, yes, on, 1 or false, no, off, 0, ignoring case.
|
| |
|
| constexpr std::uint64_t | hash (std::string_view str) noexcept |
| | 64-bit FNV-1a hash, usable at compile time.
|
| |
|
Numbers are formatted with std::format: join({1, 2, 3}, ", ") gives 1, 2, 3.
|
| template<typename Container > |
| std::string | join (const Container &parts, std::string_view separator="") |
| | Joins the elements of parts, strings or numbers, with separator between them.
|
| |
| template<typename T > |
| std::string | join (std::initializer_list< T > parts, std::string_view separator="") |
| | Joins a braced list, such as join({4, 5, 6}, "-").
|
| |
| std::string | joinString (const std::vector< std::string > &stringList, char delimiter='\0') |
| | Joins stringList with a one-character delimiter; the default adds none.
|
| |
|
An empty from matches nothing.
|
| std::size_t | replaceAll (std::string &str, std::string_view from, std::string_view to) |
| | Replaces every from in str with to and returns the number of replacements.
|
| |
| std::string | replaceAllCopy (std::string_view str, std::string_view from, std::string_view to) |
| | Returns a copy of str with every from replaced by to.
|
| |
| bool | replaceFirst (std::string &str, std::string_view from, std::string_view to) |
| | Replaces the first from in str with to; returns false if there is none.
|
| |
|
Every character of delimiters separates two parts, and empty parts are skipped.
|
| std::vector< std::string > | splitString (std::string_view str, std::string_view delimiters) |
| | Splits str into strings.
|
| |
| std::vector< std::string_view > | splitStringView (std::string_view str, std::string_view delimiters) |
| | Splits str into views, without copying: str must outlive them.
|
| |
| std::vector< std::string > | splitStringWithQuotes (std::string_view str, std::string_view delimiters, char quote='\"') |
| | Splits str, keeping the delimiters found between two quote characters and removing the quotes.
|
| |
|
| void | toLower (std::string &str) noexcept |
| | Lowercases the ASCII letters of str in place.
|
| |
| std::string | toLowerCopy (std::string_view str) |
| | Returns a copy of str with its ASCII letters lowercased.
|
| |
| void | toUpper (std::string &str) noexcept |
| | Uppercases the ASCII letters of str in place.
|
| |
| std::string | toUpperCopy (std::string_view str) |
| | Returns a copy of str with its ASCII letters uppercased.
|
| |
|
These functions remove chars, whitespace by default, from both ends of a string, or only from the left (l) or right (r) end.
View functions return a view without copying; the others trim in place or return a Copy.
|
| constexpr std::string_view | Whitespace = " \t\n\r\f\v" |
| | Characters trimmed by default: space, tab, line feed, carriage return, form feed and vertical tab.
|
| |
| constexpr std::string_view | ltrimView (std::string_view str, std::string_view chars=Whitespace) noexcept |
| |
| constexpr std::string_view | rtrimView (std::string_view str, std::string_view chars=Whitespace) noexcept |
| |
| constexpr std::string_view | trimView (std::string_view str, std::string_view chars=Whitespace) noexcept |
| |
| void | trim (std::string &str, std::string_view chars=Whitespace) |
| |
| void | ltrim (std::string &str, std::string_view chars=Whitespace) |
| |
| void | rtrim (std::string &str, std::string_view chars=Whitespace) |
| |
| std::string | trimCopy (std::string_view str, std::string_view chars=Whitespace) |
| |
| std::string | ltrimCopy (std::string_view str, std::string_view chars=Whitespace) |
| |
| std::string | rtrimCopy (std::string_view str, std::string_view chars=Whitespace) |
| |
String helpers: case, trimming, splitting, joining, replacing, parsing and hashing.
In-place functions such as trim() come with a Copy variant such as trimCopy().