A collection of general-purpose text manipulation utilities. More...
Concepts | |
| concept | sourcemeta::core::text_spellable_integer |
Typedefs | |
| using | sourcemeta::core::DigitsBuffer |
Functions | |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::to_title_case (std::string &value) -> void |
| template<typename Character> | |
| constexpr auto | sourcemeta::core::to_lowercase (const Character character) noexcept -> Character |
| template<typename Character, typename Traits, typename Allocator> | |
| auto | sourcemeta::core::to_lowercase (std::basic_string< Character, Traits, Allocator > &value) -> void |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::to_lowercase (std::filesystem::path &value) -> void |
| template<typename Character> | |
| constexpr auto | sourcemeta::core::is_lowercase (const Character character) noexcept -> bool |
| template<typename String> | |
| auto | sourcemeta::core::is_lowercase (const String &value) noexcept -> bool |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::is_lowercase (const std::filesystem::path &value) noexcept -> bool |
| template<typename Character> | |
| constexpr auto | sourcemeta::core::is_alpha (const Character character) noexcept -> bool |
| constexpr auto | sourcemeta::core::is_alpha (const std::string_view value) noexcept -> bool |
| template<typename Character> | |
| constexpr auto | sourcemeta::core::is_digit (const Character character) noexcept -> bool |
| constexpr auto | sourcemeta::core::is_digit (const std::string_view value) noexcept -> bool |
| template<typename Character> | |
| constexpr auto | sourcemeta::core::is_alphanum (const Character character) noexcept -> bool |
| constexpr auto | sourcemeta::core::is_alphanum (const std::string_view value) noexcept -> bool |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::truncate (std::string &input, const std::size_t maximum_length, const std::string_view marker) -> void |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::replace (const std::string_view input, const std::string_view target, const std::string_view replacement) -> std::string |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::trim (const std::string_view input) noexcept -> std::string_view |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::strip_left (const std::string_view input, const char character) noexcept -> std::string_view |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::strip_right (const std::string_view input, const char character) noexcept -> std::string_view |
| constexpr auto | sourcemeta::core::unquote (const std::string_view input, const char quote) noexcept -> std::string_view |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::pad_left (const std::string_view input, const std::size_t width, const char character) -> std::string |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::take_until (const std::string_view input, const char marker) noexcept -> std::string_view |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::split_once (const std::string_view input, const char delimiter) noexcept -> std::optional< std::pair< std::string_view, std::string_view > > |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::split_once (const std::string_view input, const std::string_view delimiter) noexcept -> std::optional< std::pair< std::string_view, std::string_view > > |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::rsplit_once (const std::string_view input, const char delimiter) noexcept -> std::optional< std::pair< std::string_view, std::string_view > > |
| template<typename Callback> | |
| auto | sourcemeta::core::split (const std::string_view input, const char delimiter, Callback callback) -> void |
| auto | sourcemeta::core::split (const std::string_view input, const char delimiter) -> std::vector< std::string_view > |
| template<typename Range> | |
| auto | sourcemeta::core::join (const Range &items, const std::string_view separator) -> std::string |
| template<typename Range> | |
| auto | sourcemeta::core::join_to (std::ostream &stream, const Range &items, const std::string_view separator) -> void |
| template<typename Integer, std::size_t Capacity> | |
| auto | sourcemeta::core::digits_view (const Integer value, std::array< char, Capacity > &buffer) noexcept -> std::string_view |
| template<typename Output, typename Integer> | |
| auto | sourcemeta::core::digits_append (Output &output, const Integer value) -> void |
| template<typename CharT, typename Traits, typename Integer> | |
| auto | sourcemeta::core::digits_write (std::basic_ostream< CharT, Traits > &stream, const Integer value) -> void |
| auto | sourcemeta::core::hex_digit_value (const char character) noexcept -> std::int8_t |
| auto | sourcemeta::core::is_hex_digit (const char character) noexcept -> bool |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::hex_to_bytes (const std::string_view input, const bool allow_odd_length=false) -> std::optional< std::string > |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::bytes_to_hex (const std::string_view input) -> std::string |
| auto | sourcemeta::core::equals_ignore_case (const std::string_view left, const std::string_view right) noexcept -> bool |
| auto | sourcemeta::core::starts_with_ignore_case (const std::string_view value, const std::string_view prefix) noexcept -> bool |
| auto | sourcemeta::core::less_ignore_case (const std::string_view left, const std::string_view right) noexcept -> bool |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::squeeze (const std::string_view input, const char character) -> std::string |
| template<typename Output> | |
| auto | sourcemeta::core::squeeze (const std::string_view input, const char character, Output &output) -> void |
| SOURCEMETA_CORE_TEXT_EXPORT auto | sourcemeta::core::remove_suffix_ignore_case (const std::string_view input, const std::string_view suffix) noexcept -> std::string_view |
Variables | |
| template<typename Integer> | |
| constexpr std::size_t | sourcemeta::core::digits_capacity |
A collection of general-purpose text manipulation utilities.
This functionality is included as follows:
A buffer wide enough for the decimal spelling of any integer of up to 64 bits, including a leading sign. That bound is twenty characters, reached by both the largest unsigned value and the smallest signed one.
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::bytes_to_hex | ( | const std::string_view | input | ) | -> std::string |
Encode a byte sequence as a lowercase hexadecimal string. For example:
|
inline |
Append the decimal spelling of an integer to a string like output sink. For example:
|
inlinenoexcept |
Write the decimal spelling of an integer into a caller-provided buffer, returning a view of the characters written. That view stays valid for as long as the buffer does. For example:
Use this when the result feeds a lookup or another view-taking interface. It never consults a locale, so a digit grouping separator can never appear in the result.
Any sufficiently large buffer is accepted, so a caller that only ever formats a narrow type can size one down to its capacity. Requiring the buffer to fit the widest possible value is what makes the conversion unable to fail, which is why it reports no error.
|
inline |
Write the decimal spelling of an integer to a stream. For example:
Prefer this to the stream insertion operator wherever the output has a machine-readable grammar. Insertion formats through the stream's imbued locale, so a locale carrying a digit grouping separator would otherwise break the result apart.
|
inlinenoexcept |
Return whether two strings are equal under ASCII case-insensitive comparison. For example:
This comparison is allocation-free, as it compares the lowercase form of each character without materialising lowercased copies of its arguments.
|
inlinenoexcept |
Decode a single hexadecimal digit into its numeric value, returning a negative value when the character is not a hexadecimal digit. Both letter cases are accepted. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::hex_to_bytes | ( | const std::string_view | input, |
| const bool | allow_odd_length = false ) -> std::optional< std::string > |
Decode a hexadecimal string into its raw bytes, returning no value when the input contains a character outside the hexadecimal alphabet, or has an odd length unless allow_odd_length is set, in which case a leading zero nibble is assumed. Both letter cases are accepted. For example:
|
inlineconstexprnoexcept |
Return whether a character is an ASCII letter (A-Z or a-z). For example:
|
inlineconstexprnoexcept |
Return whether a string is non-empty and consists entirely of ASCII letters (A-Z or a-z). An empty string is not considered a match. For example:
|
inlineconstexprnoexcept |
Return whether a character is an ASCII letter or digit. For example:
|
inlineconstexprnoexcept |
Return whether a string is non-empty and consists entirely of ASCII letters or digits. An empty string is not considered a match. For example:
|
inlineconstexprnoexcept |
Return whether a character is an ASCII digit (0-9). For example:
|
inlineconstexprnoexcept |
Return whether a string is non-empty and consists entirely of ASCII digits (0-9). An empty string is not considered a match. For example:
|
inlinenoexcept |
Check whether the given character is an ASCII hexadecimal digit ('0'-'9', 'a'-'f', 'A'-'F'). For example:
|
inlineconstexprnoexcept |
Return whether a character is not ASCII uppercase. For example:
|
noexcept |
Return whether every code unit of a filesystem path is not ASCII uppercase. For example:
|
inlinenoexcept |
Return whether every code unit of a string is not ASCII uppercase. For example:
| auto sourcemeta::core::join | ( | const Range & | items, |
| const std::string_view | separator ) -> std::string |
Return the items of items as a string, separated by separator. The items must be string-like, as nothing is formatted along the way. For example:
| auto sourcemeta::core::join_to | ( | std::ostream & | stream, |
| const Range & | items, | ||
| const std::string_view | separator ) -> void |
Stream each item of items to stream, separated by separator. For example:
|
inlinenoexcept |
Return whether one string orders before another under ASCII case-insensitive lexicographic comparison, which is useful as a sort comparator. For example:
Like the equality comparison, this is allocation-free.
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::pad_left | ( | const std::string_view | input, |
| const std::size_t | width, | ||
| const char | character ) -> std::string |
Return input left-padded with character to at least width bytes, or a copy of input when it is already that long. For example:
|
noexcept |
Return input with suffix removed from the end under ASCII case-insensitive comparison, or input unchanged when the suffix does not match. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::replace | ( | const std::string_view | input, |
| const std::string_view | target, | ||
| const std::string_view | replacement ) -> std::string |
Return input with every occurrence of target replaced by replacement. An empty target matches nothing. For example:
|
noexcept |
Split input at the last occurrence of delimiter, returning the parts before and after it. Return std::nullopt when the delimiter is absent. For example:
|
inline |
Return the parts of input separated by delimiter as a vector, preserving empty parts. The parts are views into input, which must outlive them. For example:
| auto sourcemeta::core::split | ( | const std::string_view | input, |
| const char | delimiter, | ||
| Callback | callback ) -> void |
Iterate the parts of input separated by delimiter, invoking callback with each part. For example:
|
noexcept |
Split input at the first occurrence of delimiter, returning the parts before and after it. Return std::nullopt when the delimiter is absent. For example:
|
noexcept |
Split input at the first occurrence of delimiter, returning the parts before and after it. Return std::nullopt when the delimiter is absent or empty. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::squeeze | ( | const std::string_view | input, |
| const char | character ) -> std::string |
Collapse consecutive runs of a character into a single occurrence. For example:
| auto sourcemeta::core::squeeze | ( | const std::string_view | input, |
| const char | character, | ||
| Output & | output ) -> void |
Collapse consecutive runs of a character into a single occurrence, appending the result to a string like output sink rather than allocating a new string. The output must not alias the input. For example:
|
inlinenoexcept |
Return whether value begins with prefix under ASCII case-insensitive comparison. For example:
Like the other case-insensitive comparisons, this is allocation-free.
|
noexcept |
Return input with leading occurrences of character removed. For example:
|
noexcept |
Return input with trailing occurrences of character removed. For example:
|
noexcept |
Return the prefix of input up to (but excluding) the first occurrence of marker, or the full input when marker is absent. For example:
|
inlineconstexprnoexcept |
Return the ASCII lowercase form of a character. Non-ASCII code units pass through unchanged. For example:
|
inline |
Convert a string to ASCII lowercase in place. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::to_lowercase | ( | std::filesystem::path & | value | ) | -> void |
Convert a filesystem path to ASCII lowercase in place. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::to_title_case | ( | std::string & | value | ) | -> void |
Convert a string to Title Case in place. For example:
|
noexcept |
Return input with leading and trailing ASCII whitespace removed. For example:
| SOURCEMETA_CORE_TEXT_EXPORT auto sourcemeta::core::truncate | ( | std::string & | input, |
| const std::size_t | maximum_length, | ||
| const std::string_view | marker ) -> void |
Truncate a string in place to at most maximum_length bytes, appending marker on truncation. Rewinds to a UTF-8 code-point boundary so multi-byte characters are never split. For example:
|
inlineconstexprnoexcept |
Return the content of input with a single matched pair of surrounding quote characters removed, or input unchanged when it is not wrapped in that pair. For example:
|
inlineconstexpr |
The exact number of characters that the decimal spelling of an integer type can require. The largest magnitude needs one character more than the type represents without loss, and a signed type needs one more again for a sign.