namespace
#include <Corrade/Utility/String.h>
String String utilities.
Contents
- Reference
This library is built if WITH_UTILITY
is enabled when building Corrade. To use this library with CMake, request the Utility
component of the Corrade
package and link to the Corrade::Utility
target.
find_package(Corrade REQUIRED Utility) # ... target_link_libraries(your-app PRIVATE Corrade::Utility)
See also Downloading and building Corrade and Using Corrade with CMake for more information.
Functions
-
auto fromArray(const char* string) -> std::
string - Safely construct string from char array.
-
auto fromArray(const char* string,
std::
size_t length) -> std:: string - Safely construct string from char array with explicit length.
-
auto ltrim(std::
string string, const std:: string& characters) -> std:: string - Trim leading characters from string.
-
template<std::auto ltrim(std::
size_t size> string string, const char(&characters)[size]) -> std:: string -
auto ltrim(std::
string string) -> std:: string - Trim leading whitespace from string.
-
auto rtrim(std::
string string, const std:: string& characters) -> std:: string - Trim trailing characters from string.
-
template<std::auto rtrim(std::
size_t size> string string, const char(&characters)[size]) -> std:: string -
auto rtrim(std::
string string) -> std:: string - Trim trailing whitespace from string.
-
auto trim(std::
string string, const std:: string& characters) -> std:: string - Trim leading and trailing characters from string.
-
template<std::auto trim(std::
size_t size> string string, const char(&characters)[size]) -> std:: string -
auto trim(std::
string string) -> std:: string - Trim leading and trailing whitespace from string.
-
void ltrimInPlace(std::
string& string, const std:: string& characters) - Trim leading characters from string, in place.
-
template<std::void ltrimInPlace(std::
size_t size> string& string, const char(&characters)[size]) -
void ltrimInPlace(std::
string& string) - Trim leading whitespace from string.
-
void rtrimInPlace(std::
string& string, const std:: string& characters) - Trim trailing characters from string.
-
template<std::void rtrimInPlace(std::
size_t size> string& string, const char(&characters)[size]) -
void rtrimInPlace(std::
string& string) - Trim trailing whitespace from string.
-
void trimInPlace(std::
string& string, const std:: string& characters) - Trim leading and trailing characters from string.
-
template<std::void trimInPlace(std::
size_t size> string& string, const char(&characters)[size]) -
void trimInPlace(std::
string& string) - Trim leading and trailing whitespace from string.
-
auto split(const std::
string& string, char delimiter) -> std:: vector<std:: string> - Split string on given character.
-
auto split(Containers::
StringView string, char delimiter) -> Containers:: Array<Containers:: StringView> deprecated in Git master -
auto splitWithoutEmptyParts(const std::
string& string, char delimiter) -> std:: vector<std:: string> - Split string on given character and remove empty parts.
-
auto splitWithoutEmptyParts(Containers::
StringView string, char delimiter) -> Containers:: Array<Containers:: StringView> deprecated in Git master -
auto splitWithoutEmptyParts(const std::
string& string, const std:: string& delimiters) -> std:: vector<std:: string> - Split string on any character from given set and remove empty parts.
-
auto splitWithoutEmptyParts(Containers::
StringView string, Containers:: StringView delimiters) -> Containers:: Array<Containers:: StringView> deprecated in Git master -
auto splitWithoutEmptyParts(const std::
string& string) -> std:: vector<std:: string> - Split string on whitespaces and remove empty parts.
-
auto splitWithoutEmptyParts(const Containers::
StringView string) -> Containers:: Array<Containers:: StringView> deprecated in Git master -
auto partition(const std::
string& string, char separator) -> Containers:: StaticArray<3, std:: string> new in 2019.10 - Partition a string.
-
auto partition(const std::
string& string, const std:: string& separator) -> Containers:: StaticArray<3, std:: string> new in 2019.10 -
auto rpartition(const std::
string& string, char separator) -> Containers:: StaticArray<3, std:: string> new in 2019.10 - Right-partition a string.
-
auto rpartition(const std::
string& string, const std:: string& separator) -> Containers:: StaticArray<3, std:: string> new in 2019.10 -
auto join(const std::
vector<std:: string>& strings, char delimiter) -> std:: string - Join strings with given character.
-
template<std::auto join(const std::
size_t size> vector<std:: string>& strings, const char(&delimiter)[size]) -> std:: string new in 2019.10 -
auto join(const std::
vector<std:: string>& strings, const std:: string& delimiter) -> std:: string new in 2019.10 -
auto joinWithoutEmptyParts(const std::
vector<std:: string>& strings, char delimiter) -> std:: string - Join strings with given character and remove empty parts.
-
template<std::auto joinWithoutEmptyParts(const std::
size_t size> vector<std:: string>& strings, const char(&delimiter)[size]) -> std:: string -
auto joinWithoutEmptyParts(const std::
vector<std:: string>& strings, const std:: string& delimiter) -> std:: string -
auto lowercase(std::
string string) -> std:: string - Convert string to lowercase.
-
auto uppercase(std::
string string) -> std:: string - Convert string to uppercase.
-
auto beginsWith(const std::
string& string, const std:: string& prefix) -> bool - Whether the string has given prefix.
-
template<std::auto beginsWith(const std::
size_t size> string& string, const char(&prefix)[size]) -> bool -
auto beginsWith(const std::
string& string, char prefix) -> bool -
template<std::auto viewBeginsWith(Containers::
size_t size> ArrayView<const char> string, const char(&prefix)[size]) -> bool deprecated in Git master - Whether string view has given prefix.
-
auto viewBeginsWith(Containers::
ArrayView<const char> string, char prefix) -> bool deprecated in Git master -
auto endsWith(const std::
string& string, const std:: string& suffix) -> bool - Whether the string has given suffix.
-
template<std::auto endsWith(const std::
size_t size> string& string, const char(&suffix)[size]) -> bool -
auto endsWith(const std::
string& string, char suffix) -> bool -
template<std::auto viewEndsWith(Containers::
size_t size> ArrayView<const char> string, const char(&suffix)[size]) -> bool deprecated in Git master - Whether string view has given suffix.
-
auto viewEndsWith(Containers::
ArrayView<const char> string, char suffix) -> bool deprecated in Git master -
auto stripPrefix(std::
string string, const std:: string& prefix) -> std:: string - Strip given prefix from a string.
-
template<std::auto stripPrefix(std::
size_t size> string string, const char(&prefix)[size]) -> std:: string -
auto stripPrefix(std::
string string, char prefix) -> std:: string -
auto stripSuffix(std::
string string, const std:: string& suffix) -> std:: string - Strip given suffix from a string.
-
template<std::auto stripSuffix(std::
size_t size> string string, const char(&suffix)[size]) -> std:: string -
auto stripSuffix(std::
string string, char suffix) -> std:: string -
auto replaceFirst(std::
string string, const std:: string& search, const std:: string& replace) -> std:: string - Replace first occurence in a string.
-
template<std::auto replaceFirst(std::
size_t searchSize, std:: size_t replaceSize> string string, const char(&search)[searchSize], const char(&replace)[replaceSize]) -> std:: string -
template<std::auto replaceFirst(std::
size_t searchSize> string string, const char(&search)[searchSize], const std:: string& replace) -> std:: string -
template<std::auto replaceFirst(std::
size_t replaceSize> string string, const std:: string& search, const char(&replace)[replaceSize]) -> std:: string -
auto replaceAll(std::
string string, const std:: string& search, const std:: string& replace) -> std:: string - Replace all occurences in a string.
-
template<std::auto replaceAll(std::
size_t searchSize, std:: size_t replaceSize> string string, const char(&search)[searchSize], const char(&replace)[replaceSize]) -> std:: string -
template<std::auto replaceAll(std::
size_t searchSize> string string, const char(&search)[searchSize], const std:: string& replace) -> std:: string -
template<std::auto replaceAll(std::
size_t replaceSize> string string, const std:: string& search, const char(&replace)[replaceSize]) -> std:: string
Function documentation
std:: string Corrade:: Utility:: String:: fromArray(const char* string)
Safely construct string from char array.
If string
is nullptr
, returns empty string.
std:: string Corrade:: Utility:: String:: fromArray(const char* string,
std:: size_t length)
Safely construct string from char array with explicit length.
If string
is nullptr
, returns empty string. Otherwise takes also length
into account.
std:: string Corrade:: Utility:: String:: ltrim(std:: string string,
const std:: string& characters)
Trim leading characters from string.
Parameters | |
---|---|
string | String to be trimmed |
characters | Characters which will be trimmed |
Implemented using ltrimInPlace().
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: ltrim(std:: string string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: ltrim(std:: string string)
Trim leading whitespace from string.
Equivalent to calling ltrim(std::" \t\f\v\r\n"
as second parameter. Implemented using ltrimInPlace().
std:: string Corrade:: Utility:: String:: rtrim(std:: string string,
const std:: string& characters)
Trim trailing characters from string.
Parameters | |
---|---|
string | String to be trimmed |
characters | Characters which will be trimmed |
Implemented using rtrimInPlace().
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: rtrim(std:: string string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: rtrim(std:: string string)
Trim trailing whitespace from string.
Equivalent to calling rtrim(std::" \t\f\v\r\n"
as second parameter. Implemented using trimInPlace().
std:: string Corrade:: Utility:: String:: trim(std:: string string,
const std:: string& characters)
Trim leading and trailing characters from string.
Parameters | |
---|---|
string | String to be trimmed |
characters | Characters which will be trimmed |
Equivalent to ltrim(rtrim(string, characters), characters)
. Implemented using trimInPlace().
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: trim(std:: string string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: trim(std:: string string)
Trim leading and trailing whitespace from string.
Equivalent to calling trim(std::" \t\f\v\r\n"
as second parameter. Implemented using trimInPlace().
void Corrade:: Utility:: String:: ltrimInPlace(std:: string& string,
const std:: string& characters)
Trim leading characters from string, in place.
Parameters | |
---|---|
string | String to be trimmed in place |
characters | Characters which will be trimmed |
template<std:: size_t size>
void Corrade:: Utility:: String:: ltrimInPlace(std:: string& string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Corrade:: Utility:: String:: ltrimInPlace(std:: string& string)
Trim leading whitespace from string.
Equivalent to calling ltrimInPlace(std::" \t\f\v\r\n"
as second parameter.
void Corrade:: Utility:: String:: rtrimInPlace(std:: string& string,
const std:: string& characters)
Trim trailing characters from string.
Parameters | |
---|---|
string | String to be trimmed |
characters | Characters which will be trimmed |
template<std:: size_t size>
void Corrade:: Utility:: String:: rtrimInPlace(std:: string& string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Corrade:: Utility:: String:: rtrimInPlace(std:: string& string)
Trim trailing whitespace from string.
Equivalent to calling rtrimInPlace(std::" \t\f\v\r\n"
as second parameter.
void Corrade:: Utility:: String:: trimInPlace(std:: string& string,
const std:: string& characters)
Trim leading and trailing characters from string.
Parameters | |
---|---|
string | String to be trimmed |
characters | Characters which will be trimmed |
Equivalent to calling both ltrimInPlace() and rtrimInPlace().
template<std:: size_t size>
void Corrade:: Utility:: String:: trimInPlace(std:: string& string,
const char(&characters)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void Corrade:: Utility:: String:: trimInPlace(std:: string& string)
Trim leading and trailing whitespace from string.
Equivalent to calling trimInPlace(std::" \t\f\v\r\n"
as second parameter.
std:: vector<std:: string> Corrade:: Utility:: String:: split(const std:: string& string,
char delimiter)
Split string on given character.
Parameters | |
---|---|
string | String to split |
delimiter | Delimiter |
Containers:: Array<Containers:: StringView> Corrade:: Utility:: String:: split(Containers:: StringView string,
char delimiter)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: vector<std:: string> Corrade:: Utility:: String:: splitWithoutEmptyParts(const std:: string& string,
char delimiter)
Split string on given character and remove empty parts.
Parameters | |
---|---|
string | String to split |
delimiter | Delimiter |
Containers:: Array<Containers:: StringView> Corrade:: Utility:: String:: splitWithoutEmptyParts(Containers:: StringView string,
char delimiter)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: vector<std:: string> Corrade:: Utility:: String:: splitWithoutEmptyParts(const std:: string& string,
const std:: string& delimiters)
Split string on any character from given set and remove empty parts.
Parameters | |
---|---|
string | String to split |
delimiters | Delimiter characters |
Containers:: Array<Containers:: StringView> Corrade:: Utility:: String:: splitWithoutEmptyParts(Containers:: StringView string,
Containers:: StringView delimiters)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: vector<std:: string> Corrade:: Utility:: String:: splitWithoutEmptyParts(const std:: string& string)
Split string on whitespaces and remove empty parts.
Equivalent to calling splitWithoutEmptyParts(const std::" \t\f\v\r\n"
as second parameter.
Containers:: Array<Containers:: StringView> Corrade:: Utility:: String:: splitWithoutEmptyParts(const Containers:: StringView string)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Containers:: StaticArray<3, std:: string> Corrade:: Utility:: String:: partition(const std:: string& string,
char separator) new in 2019.10
Partition a string.
Equivalent to Python's str.partition(). Splits string
at the first occurence of separator
. First returned value is the part before the separator, second the separator, third a part after the separator. If the separator is not found, returns the input string followed by two empty strings.
Containers:: StaticArray<3, std:: string> Corrade:: Utility:: String:: partition(const std:: string& string,
const std:: string& separator) new in 2019.10
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Containers:: StaticArray<3, std:: string> Corrade:: Utility:: String:: rpartition(const std:: string& string,
char separator) new in 2019.10
Right-partition a string.
Equivalent to Python's str.rpartition(). Splits string
at the last occurence of separator
. First returned value is the part before the separator, second the separator, third a part after the separator. If the separator is not found, returns two empty strings followed by the input string.
Containers:: StaticArray<3, std:: string> Corrade:: Utility:: String:: rpartition(const std:: string& string,
const std:: string& separator) new in 2019.10
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: join(const std:: vector<std:: string>& strings,
char delimiter)
Join strings with given character.
Parameters | |
---|---|
strings | Strings to join |
delimiter | Delimiter |
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: join(const std:: vector<std:: string>& strings,
const char(&delimiter)[size]) new in 2019.10
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: join(const std:: vector<std:: string>& strings,
const std:: string& delimiter) new in 2019.10
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: joinWithoutEmptyParts(const std:: vector<std:: string>& strings,
char delimiter)
Join strings with given character and remove empty parts.
Parameters | |
---|---|
strings | Strings to join |
delimiter | Delimiter |
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: joinWithoutEmptyParts(const std:: vector<std:: string>& strings,
const char(&delimiter)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: joinWithoutEmptyParts(const std:: vector<std:: string>& strings,
const std:: string& delimiter)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: lowercase(std:: string string)
Convert string to lowercase.
std:: string Corrade:: Utility:: String:: uppercase(std:: string string)
Convert string to uppercase.
bool Corrade:: Utility:: String:: beginsWith(const std:: string& string,
const std:: string& prefix)
Whether the string has given prefix.
In particular, returns true
for empty string
only if prefix
is empty as well.
template<std:: size_t size>
bool Corrade:: Utility:: String:: beginsWith(const std:: string& string,
const char(&prefix)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool Corrade:: Utility:: String:: beginsWith(const std:: string& string,
char prefix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t size>
bool Corrade:: Utility:: String:: viewBeginsWith(Containers:: ArrayView<const char> string,
const char(&prefix)[size])
Whether string view has given prefix.
bool Corrade:: Utility:: String:: viewBeginsWith(Containers:: ArrayView<const char> string,
char prefix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool Corrade:: Utility:: String:: endsWith(const std:: string& string,
const std:: string& suffix)
Whether the string has given suffix.
In particular, returns true
for empty string
only if suffix
is empty as well.
template<std:: size_t size>
bool Corrade:: Utility:: String:: endsWith(const std:: string& string,
const char(&suffix)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool Corrade:: Utility:: String:: endsWith(const std:: string& string,
char suffix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t size>
bool Corrade:: Utility:: String:: viewEndsWith(Containers:: ArrayView<const char> string,
const char(&suffix)[size])
Whether string view has given suffix.
bool Corrade:: Utility:: String:: viewEndsWith(Containers:: ArrayView<const char> string,
char suffix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: stripPrefix(std:: string string,
const std:: string& prefix)
Strip given prefix from a string.
Expects that the string actually begins with given prefix.
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: stripPrefix(std:: string string,
const char(&prefix)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: stripPrefix(std:: string string,
char prefix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: stripSuffix(std:: string string,
const std:: string& suffix)
Strip given suffix from a string.
Expects that the string actually ends with given suffix.
template<std:: size_t size>
std:: string Corrade:: Utility:: String:: stripSuffix(std:: string string,
const char(&suffix)[size])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: stripSuffix(std:: string string,
char suffix)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: replaceFirst(std:: string string,
const std:: string& search,
const std:: string& replace)
Replace first occurence in a string.
Returns string
unmodified if it doesn't contain search
. Having empty search
causes replace
to be prepended to string
.
template<std:: size_t searchSize, std:: size_t replaceSize>
std:: string Corrade:: Utility:: String:: replaceFirst(std:: string string,
const char(&search)[searchSize],
const char(&replace)[replaceSize])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t searchSize>
std:: string Corrade:: Utility:: String:: replaceFirst(std:: string string,
const char(&search)[searchSize],
const std:: string& replace)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t replaceSize>
std:: string Corrade:: Utility:: String:: replaceFirst(std:: string string,
const std:: string& search,
const char(&replace)[replaceSize])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
std:: string Corrade:: Utility:: String:: replaceAll(std:: string string,
const std:: string& search,
const std:: string& replace)
Replace all occurences in a string.
Returns string
unmodified if it doesn't contain search
. Expects that search
is not empty, as that would cause an infinite loop.
template<std:: size_t searchSize, std:: size_t replaceSize>
std:: string Corrade:: Utility:: String:: replaceAll(std:: string string,
const char(&search)[searchSize],
const char(&replace)[replaceSize])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t searchSize>
std:: string Corrade:: Utility:: String:: replaceAll(std:: string string,
const char(&search)[searchSize],
const std:: string& replace)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<std:: size_t replaceSize>
std:: string Corrade:: Utility:: String:: replaceAll(std:: string string,
const std:: string& search,
const char(&replace)[replaceSize])
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.