This header provides user friendly UTF-8 and UTF-32 string utility functions, defined within the Balau::Util::Strings namespace.
UTF-16 versions of the utilities are not current implemented. Pull requests with such new functionality are welcome.
These utility functions provide more coarse grained functionality compared to that provided by ICU, Boost, and the C++ standard library string manipulation calls.
The utilities use and return std::string_view objects where possible. In order to support multiple string types, a two stage typename deduction / type conversion approach is used for many of the functions.
#include <Balau/Util/Strings.hpp>
The following utilities are currently implemented. More information is available on the API documentation page.
https://borasoftware.com/doc/balau/latest/api/structBalau_1_1Util_1_1Strings.htmlEach function covers UTF-8 and UTF-32 encodings and is available in several forms.
Function name | Description |
---|---|
startsWith | Does the first string start with the second string/character/code point? |
endsWith | Does the first string end with the second string/character/code point? |
contains | Does the first string contain the second string/character/code point? |
occurrences | How many non-overlapping occurrences of the second string/regular expression are found in the first string? |
equalsIgnoreCase | Ignoring case, is the first string equal to the second string? |
lineLengths | Given the supplied multi-line text string and an optional line break regular expression, determine the lengths of the lines in bytes. |
lastIndexOf | Get the character/code point position in the first string of the last index of the second string. |
codePointCount | Count the number of code points in the supplied string. |
Function name | Description |
---|---|
toUpper | Convert the string to uppercase. |
toLower | Convert the string to lowercase. |
append | Appends count times the supplied character/code point to the supplied string. |
padLeft | Left pad the string up to the specified width in code points, using the supplied character/code point. |
padRight | Right pad the string up to the specified width in code points, using the supplied character/code point. |
trim | Trim whitespace from the beginning and end of the string. |
trimLeft | Trim whitespace from the beginning of the string. |
trimRight | Trim whitespace from the end of the string. |
replaceAll | Replace all occurrences of the specified string/regular expression with the specified replacement. |
Function name | Description |
---|---|
join | Join the strings together, separated by the supplied delimiter. |
prefixSuffixJoin | Join the strings together, prefixing each string with the prefix and suffixing each string with the suffix. |
split | Split the string on each of the occurrences of the specified string/regular expression delimiter. |