String namespace
String utilities.
This library is built if CORRADE_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.
Classes
- class ParseResult new in Git master
- String parse result.
Enums
-
enum class ParseState: std::
uint8_t { Success, Clamped, Failed } new in Git master - String parse state.
-
enum class ParseDecimalFlag: std::
uint8_t { DisallowSign = 1 << 0 } new in Git master - Decimal string parse flag.
-
enum class ParseHexadecimalFlag: std::
uint8_t { DisallowSign = 1 << 0, AllowBasePrefix = 1 << 1, AllowHashPrefix = 1 << 2 } new in Git master - Hexadecimal string parse flag.
-
enum class ParseFloatFlag: std::
uint8_t { DisallowSign = 1 << 0 } new in Git master - Float string parse flag.
Typedefs
-
using ParseDecimalFlags = Containers::
EnumSet<ParseDecimalFlag> new in Git master - Decimal string parse flags.
-
using ParseHexadecimalFlags = Containers::
EnumSet<ParseHexadecimalFlag> new in Git master - Hexadecimal string parse flags.
-
using ParseFloatFlags = Containers::
EnumSet<ParseFloatFlag> new in Git master - Float string parse flags.
Functions
-
auto commonPrefix(Containers::
StringView a, Containers:: StringView b) -> Containers:: StringView new in Git master - Longest common prefix of two strings.
-
void lowercaseInPlace(Containers::
MutableStringView string) new in Git master - Convert ASCII characters in a string to lowercase, in place.
-
auto lowercase(Containers::
StringView string) -> Containers:: String new in Git master - Convert ASCII characters in a string to lowercase.
-
auto lowercase(Containers::
String string) -> Containers:: String new in Git master -
void uppercaseInPlace(Containers::
MutableStringView string) new in Git master - Convert ASCII characters in a string to uppercase, in place.
-
auto uppercase(Containers::
StringView string) -> Containers:: String new in Git master - Convert ASCII characters in a string to uppercase, in place.
-
auto uppercase(Containers::
String string) -> Containers:: String new in Git master -
auto replaceFirst(Containers::
StringView string, Containers:: StringView search, Containers:: StringView replace) -> Containers:: String new in Git master - Replace first occurrence in a string.
-
auto replaceAll(Containers::
StringView string, Containers:: StringView search, Containers:: StringView replace) -> Containers:: String new in Git master - Replace all occurrences in a string.
-
auto replaceAll(Containers::
String string, char search, char replace) -> Containers:: String new in Git master - Replace all occurrences of a character in a string with another character.
-
void replaceAllInPlace(const Containers::
MutableStringView string, const char search, const char replace) new in Git master - Replace all occurrences of a character in a string with another character in-place.
-
auto operator<<(Utility::
Debug& debug, ParseState value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto operator<<(Utility::
Debug& debug, ParseDecimalFlag value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto operator<<(Utility::
Debug& debug, ParseDecimalFlags value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto parseDecimal(Containers::
StringView string, std:: uint64_t& value, std:: uint64_t min, std:: uint64_t max, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: int64_t& value, std:: int64_t min, std:: int64_t max, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: uint8_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 8-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: int8_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 8-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: uint16_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 16-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: int16_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 16-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: uint32_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 32-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: int32_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 32-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: uint64_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 64-bit decimal number.
-
auto parseDecimal(Containers::
StringView string, std:: int64_t& value, ParseDecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 64-bit decimal number.
-
auto operator<<(Utility::
Debug& debug, ParseHexadecimalFlag value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto operator<<(Utility::
Debug& debug, ParseHexadecimalFlags value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto parseHexadecimal(Containers::
StringView string, std:: uint64_t& value, std:: uint64_t min, std:: uint64_t max, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: int64_t& value, std:: int64_t min, std:: int64_t max, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: uint8_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 8-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: int8_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 8-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: uint16_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 16-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: int16_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 16-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: uint32_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 32-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: int32_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 32-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: uint64_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing an unsigned 64-bit hexadecimal number.
-
auto parseHexadecimal(Containers::
StringView string, std:: int64_t& value, ParseHexadecimalFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a signed 64-bit hexadecimal number.
-
auto operator<<(Utility::
Debug& debug, ParseFloatFlag value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto operator<<(Utility::
Debug& debug, ParseFloatFlags value) -> Utility:: Debug& new in Git master - Debug output operator.
-
auto parseFloat(Containers::
StringView string, float& value, ParseFloatFlags flags = {}) -> ParseResult new in Git master - Parse a string containing a floating-point number.
-
auto parseFloat(Containers::
StringView string, double& value, ParseFloatFlags flags = {}) -> ParseResult new in Git master -
auto parseNumberSequence(Containers::
StringView string, std:: uint32_t min, std:: uint32_t max) -> Containers:: Optional<Containers:: Array<std:: uint32_t>> new in Git master - Parse a number sequence.
-
auto fromArray(const char* string) -> std::
string deprecated in Git master - Safely construct string from char array.
-
auto fromArray(const char* string,
std::
size_t length) -> std:: string deprecated in Git master - Safely construct string from char array with explicit length.
-
auto ltrim(std::
string string, const std:: string& characters) -> std:: string deprecated in Git master - Trim leading characters from string.
-
auto ltrim(std::
string string) -> std:: string deprecated in Git master - Trim leading whitespace from string.
-
auto rtrim(std::
string string, const std:: string& characters) -> std:: string deprecated in Git master - Trim trailing characters from string.
-
auto rtrim(std::
string string) -> std:: string deprecated in Git master - Trim trailing whitespace from string.
-
auto trim(std::
string string, const std:: string& characters) -> std:: string deprecated in Git master - Trim leading and trailing characters from string.
-
auto trim(std::
string string) -> std:: string deprecated in Git master - Trim leading and trailing whitespace from string.
-
void ltrimInPlace(std::
string& string, const std:: string& characters) deprecated in Git master - Trim leading characters from a string, in place.
-
void ltrimInPlace(std::
string& string) deprecated in Git master - Trim leading whitespace from a string, in place.
-
void rtrimInPlace(std::
string& string, const std:: string& characters) deprecated in Git master - Trim trailing characters from a string, in place.
-
void rtrimInPlace(std::
string& string) deprecated in Git master - Trim trailing whitespace from a string, in place.
-
void trimInPlace(std::
string& string, const std:: string& characters) deprecated in Git master - Trim leading and trailing characters from a string, in place.
-
void trimInPlace(std::
string& string) deprecated in Git master - Trim leading and trailing whitespace from a string, in place.
-
auto split(const std::
string& string, char delimiter) -> std:: vector<std:: string> deprecated in Git master - Split a 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> deprecated in Git master - Split a 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> deprecated in Git master - Split a 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> deprecated in Git master - Split a string on whitespace 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> deprecated in Git master - Partition a string.
-
auto partition(const std::
string& string, const std:: string& separator) -> Containers:: StaticArray<3, std:: string> deprecated in Git master -
auto rpartition(const std::
string& string, char separator) -> Containers:: StaticArray<3, std:: string> deprecated in Git master - Right-partition a string.
-
auto rpartition(const std::
string& string, const std:: string& separator) -> Containers:: StaticArray<3, std:: string> deprecated in Git master -
auto join(const std::
vector<std:: string>& strings, char delimiter) -> std:: string deprecated in Git master - Join strings with given character.
-
auto join(const std::
vector<std:: string>& strings, const std:: string& delimiter) -> std:: string deprecated in Git master -
auto joinWithoutEmptyParts(const std::
vector<std:: string>& strings, char delimiter) -> std:: string deprecated in Git master - Join strings with given character and remove empty parts.
-
auto joinWithoutEmptyParts(const std::
vector<std:: string>& strings, const std:: string& delimiter) -> std:: string deprecated in Git master -
auto beginsWith(const std::
string& string, const std:: string& prefix) -> bool deprecated in Git master - Whether the string has given prefix.
-
auto beginsWith(const std::
string& string, char prefix) -> bool deprecated in Git master -
auto viewBeginsWith(Containers::
ArrayView<const char> string, Containers:: ArrayView<const char> prefix) -> 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 deprecated in Git master - Whether the string has given suffix.
-
auto endsWith(const std::
string& string, char suffix) -> bool deprecated in Git master -
auto viewEndsWith(Containers::
ArrayView<const char> string, Containers:: ArrayView<const char> suffix) -> 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 deprecated in Git master - Strip given prefix from a string.
-
auto stripPrefix(std::
string string, char prefix) -> std:: string deprecated in Git master -
auto stripSuffix(std::
string string, const std:: string& suffix) -> std:: string deprecated in Git master - Strip given suffix from a string.
-
auto stripSuffix(std::
string string, char suffix) -> std:: string deprecated in Git master
Enum documentation
enum class Corrade:: Utility:: String:: ParseState: std:: uint8_t new in Git master
#include <Corrade/Utility/String.h>
String parse state.
Returned as part of ParseResult from parseDecimal() and parseHexadecimal().
| Enumerators | |
|---|---|
| Success |
Parsing succeeded with no information loss, i.e. the value can fit into the desired range without being clamped. |
| Clamped |
Parsing succeeded but the parsed value had to be clamped to fit into the desired range. The output value is set to the appropriate min or max value of given range. |
| Failed |
Parsing the value failed, for example because it contains invalid characters. The output value is left in an unspecified state in this case, ParseResult:: |
enum class Corrade:: Utility:: String:: ParseDecimalFlag: std:: uint8_t new in Git master
#include <Corrade/Utility/String.h>
Decimal string parse flag.
| Enumerators | |
|---|---|
| DisallowSign |
Disallow |
enum class Corrade:: Utility:: String:: ParseHexadecimalFlag: std:: uint8_t new in Git master
#include <Corrade/Utility/String.h>
Hexadecimal string parse flag.
| Enumerators | |
|---|---|
| DisallowSign |
Disallow |
| AllowBasePrefix |
Allow also a |
| AllowHashPrefix |
Allow also a |
enum class Corrade:: Utility:: String:: ParseFloatFlag: std:: uint8_t new in Git master
#include <Corrade/Utility/String.h>
Float string parse flag.
| Enumerators | |
|---|---|
| DisallowSign |
Disallow |
Typedef documentation
typedef Containers:: EnumSet<ParseDecimalFlag> Corrade:: Utility:: String:: ParseDecimalFlags new in Git master
#include <Corrade/Utility/String.h>
Decimal string parse flags.
typedef Containers:: EnumSet<ParseHexadecimalFlag> Corrade:: Utility:: String:: ParseHexadecimalFlags new in Git master
#include <Corrade/Utility/String.h>
Hexadecimal string parse flags.
typedef Containers:: EnumSet<ParseFloatFlag> Corrade:: Utility:: String:: ParseFloatFlags new in Git master
#include <Corrade/Utility/String.h>
Float string parse flags.
Function documentation
Containers:: StringView Corrade:: Utility:: String:: commonPrefix(Containers:: StringView a,
Containers:: StringView b) new in Git master
#include <Corrade/Utility/String.h>
Longest common prefix of two strings.
The returned view is a prefix of a.
void Corrade:: Utility:: String:: lowercaseInPlace(Containers:: MutableStringView string) new in Git master
#include <Corrade/Utility/String.h>
Convert ASCII characters in a string to lowercase, in place.
Replaces any character from ABCDEFGHIJKLMNOPQRSTUVWXYZ with a corresponding character from abcdefghijklmnopqrstuvwxyz. Deliberately supports only ASCII as Unicode-aware case conversion is a much more complex topic.
Containers:: String Corrade:: Utility:: String:: lowercase(Containers:: StringView string) new in Git master
#include <Corrade/Utility/String.h>
Convert ASCII characters in a string to lowercase.
Allocates a copy and replaces any character from ABCDEFGHIJKLMNOPQRSTUVWXYZ with a corresponding character from abcdefghijklmnopqrstuvwxyz. Deliberately supports only ASCII as Unicode-aware case conversion is a much more complex topic.
Containers:: String Corrade:: Utility:: String:: lowercase(Containers:: String string) new in Git master
#include <Corrade/Utility/String.h>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Compared to lowercase(Containers::string is owned, transferring the data ownership to the returned instance. Makes a owned copy first if not.
void Corrade:: Utility:: String:: uppercaseInPlace(Containers:: MutableStringView string) new in Git master
#include <Corrade/Utility/String.h>
Convert ASCII characters in a string to uppercase, in place.
Replaces any character from abcdefghijklmnopqrstuvwxyz with a corresponding character from ABCDEFGHIJKLMNOPQRSTUVWXYZ. Deliberately supports only ASCII as Unicode-aware case conversion is a much more complex topic.
Containers:: String Corrade:: Utility:: String:: uppercase(Containers:: StringView string) new in Git master
#include <Corrade/Utility/String.h>
Convert ASCII characters in a string to uppercase, in place.
Allocates a copy and replaces any character from abcdefghijklmnopqrstuvwxyz with a corresponding character from ABCDEFGHIJKLMNOPQRSTUVWXYZ. Deliberately supports only ASCII as Unicode-aware case conversion is a much more complex topic.
Containers:: String Corrade:: Utility:: String:: uppercase(Containers:: String string) new in Git master
#include <Corrade/Utility/String.h>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Compared to uppercase(Containers::string is owned, transferring the data ownership to the returned instance. Makes a owned copy first if not.
Containers:: String Corrade:: Utility:: String:: replaceFirst(Containers:: StringView string,
Containers:: StringView search,
Containers:: StringView replace) new in Git master
#include <Corrade/Utility/String.h>
Replace first occurrence in a string.
Returns string unmodified if it doesn't contain search. Having empty search causes replace to be prepended to string.
Containers:: String Corrade:: Utility:: String:: replaceAll(Containers:: StringView string,
Containers:: StringView search,
Containers:: StringView replace) new in Git master
#include <Corrade/Utility/String.h>
Replace all occurrences 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. For substituting a single character with another the replaceAll(Containers::
Containers:: String Corrade:: Utility:: String:: replaceAll(Containers:: String string,
char search,
char replace) new in Git master
#include <Corrade/Utility/String.h>
Replace all occurrences of a character in a string with another character.
The string is passed through unmodified if it doesn't contain search. Otherwise the operation is performed in-place if string is owned, transferring the data ownership to the returned instance. An owned copy is made if not. See also replaceAllInPlace() for a variant that operates on string views.
void Corrade:: Utility:: String:: replaceAllInPlace(const Containers:: MutableStringView string,
const char search,
const char replace) new in Git master
#include <Corrade/Utility/String.h>
Replace all occurrences of a character in a string with another character in-place.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseState value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseDecimalFlag value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseDecimalFlags value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: uint64_t& value,
std:: uint64_t min,
std:: uint64_t max,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned decimal number.
| Parameters | |
|---|---|
| string in | Input string |
| value out | Output value |
| min in | Minimal allowed value |
| max in | Maximal allowed value |
| flags in | Flags |
| Returns | Parse state |
If the string is a decimal numeric value, optionally prepended with a + sign unless ParseDecimalFlag::value and returns ParseState::min and max. If the value doesn't fit into the range defined by min and max, returns ParseState::value is set to either min or max as appropriate. If the string isn't a valid number or has non-numeric characters before or after, returns ParseState::value left in an unspecified state.
The string can have any number of leading zeros after the sign, unlike std::0x or 0X prefix is treated as a parsing failure.
Expects that min is less or equal to max. Common usage is through one of the type-specific overloads such as parseDecimal(Containers::
std::uint32_t value; Utility::String::ParseResult result = Utility::String::parseDecimal(…, value); if(result == Utility::String::ParseState::Failed) { // handle a parsing failure ... } else if(result == Utility::String::ParseState::Clamped) { // handle value out of bounds ... } else { // handle success ... }
If clamping / overflow doesn't need to be handled, it's enough to check that the function doesn't return ParseState::
Note that in comparison to std::- sign. Furthermore, the function does not discard any whitespace characters around the number — if you need to do so, pass the string as trimmed(), with trimmedPrefix() or with trimmedSuffix():
std::uint32_t value; if(Utility::String::parseDecimal(string.trimmed(), value) != Utility::String::ParseState::Failed) { … }
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: int64_t& value,
std:: int64_t min,
std:: int64_t max,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed decimal number.
| Parameters | |
|---|---|
| string in | Input string |
| value out | Output value |
| min in | Minimal allowed value |
| max in | Maximal allowed value |
| flags in | Flags |
| Returns | Parse state |
If the string is a decimal numeric value, optionally prepended with a + or - sign unless ParseDecimalFlag::value and returns ParseState::min and max. If the value doesn't fit into the range defined by min and max, returns ParseState::value is set to either min or max as appropriate. If the string isn't a valid number or has non-numeric characters before or after, returns ParseState::value left in an unspecified state.
The string can have any number of leading zeros after the sign, if any, unlike std::0x or 0X prefix is treated as a parsing failure.
Expects that min is less or equal to max. Common usage is through one of the type-specific overloads such as parseDecimal(Containers::
std::int32_t value; Utility::String::ParseResult result = Utility::String::parseDecimal(…, value); if(result == Utility::String::ParseState::Failed) { // handle a parsing failure ... } else if(result == Utility::String::ParseState::Clamped) { // handle value out of bounds ... } else { // handle success ... }
If clamping / overflow doesn't need to be handled, it's enough to check that the function doesn't return ParseState::
Note that in comparison to std::string as trimmed(), with trimmedPrefix() or with trimmedSuffix():
std::int32_t value; if(Utility::String::parseDecimal(string.trimmed(), value) != Utility::String::ParseState::Failed) { … }
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: uint8_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 8-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to 0 and max set to 255 and converting the value to a 8-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: int8_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 8-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to -128 and max set to 127 and converting the value to a 8-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: uint16_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 16-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to 0 and max set to 65535 and converting the value to a 16-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: int16_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 16-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to -32768 and max set to 32767 and converting the value to a 16-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: uint32_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 32-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to 0 and max set to a max representable unsigned 32-bit value and converting the value to a 32-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: int32_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 32-bit decimal number.
Equivalent to calling parseDecimal(Containers::min and max set to a min and max representable signed 32-bit value and converting the value to a 32-bit type.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: uint64_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 64-bit decimal number.
Equivalent to calling parseDecimal(Containers::min set to 0 and max set to a max representable unsigned 64-bit value.
ParseResult Corrade:: Utility:: String:: parseDecimal(Containers:: StringView string,
std:: int64_t& value,
ParseDecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 64-bit decimal number.
Equivalent to calling parseDecimal(Containers::min and max set to a min and max representable signed 64-bit value.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseHexadecimalFlag value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseHexadecimalFlags value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: uint64_t& value,
std:: uint64_t min,
std:: uint64_t max,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned hexadecimal number.
| Parameters | |
|---|---|
| string in | Input string |
| value out | Output value |
| min in | Minimal allowed value |
| max in | Maximal allowed value |
| flags in | Flags |
| Returns | Parse state |
If the string is a hexadecimal numeric value, optionally prepended with a + sign unless ParseHexadecimalFlag::value and returns ParseState::min and max. If the value doesn't fit into the range defined by min and max, returns ParseState::value is set to either min or max as appropriate. If the string isn't a valid number or has non-hexadecimal characters before or after, returns ParseState::value left in an unspecified state.
Both lowercase and uppercase hexadecimal characters are accepted. By default no prefix is allowed, pass ParseHexadecimalFlag::0x or 0X after the sign, if any, and ParseHexadecimalFlag::# character after the sign, if any, such as for a hexadecimal color representation. The string can have any number of leading zeros after the sign and prefix, if any, unlike std::
Expects that min is less or equal to max. Common usage is through one of the type-specific overloads such as parseHexadecimal(Containers::
std::uint32_t value; Utility::String::ParseResult result = Utility::String::parseHexadecimal(…, value, Utility::String::ParseHexadecimalFlag::AllowBasePrefix); if(result == Utility::String::ParseState::Failed) { // handle a parsing failure ... } else if(result == Utility::String::ParseState::Clamped) { // handle value out of bounds ... } else { // handle success ... }
If clamping / overflow doesn't need to be handled, it's enough to check that the function doesn't return ParseState::
Note that in comparison to std::- sign. Furthermore, the function does not discard any whitespace characters around the number — if you need to do so, pass the string as trimmed(), with trimmedPrefix() or with trimmedSuffix():
std::uint32_t value; if(Utility::String::parseHexadecimal(string.trimmed(), value) != Utility::String::ParseState::Failed) { … }
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: int64_t& value,
std:: int64_t min,
std:: int64_t max,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed hexadecimal number.
| Parameters | |
|---|---|
| string in | Input string |
| value out | Output value |
| min in | Minimal allowed value |
| max in | Maximal allowed value |
| flags in | Flags |
| Returns | Parse state |
If the string is a hexadecimal numeric value, optionally prepended with a + or - sign unless ParseDecimalFlag::value and returns ParseState::min and max. If the value doesn't fit into the range defined by min and max, returns ParseState::value is set to either min or max as appropriate. If the string isn't a valid number or has non-hexadecimal characters before or after, returns ParseState::value left in an unspecified state.
Both lowercase and uppercase hexadecimal characters are accepted. By default no prefix is allowed, pass ParseHexadecimalFlag::0x or 0X after the sign, and ParseHexadecimalFlag::# character after the sign, such as for hexadecimal color representation. The string can have any number of leading zeros after the sign and prefix, unlike std::
Expects that min is less or equal to max. Common usage is through one of the type-specific overloads such as parseHexadecimal(Containers::
std::int32_t value; Utility::String::ParseResult result = Utility::String::parseHexadecimal(…, value, Utility::String::ParseHexadecimalFlag::AllowBasePrefix); if(result == Utility::String::ParseState::Failed) { // handle a parsing failure ... } else if(result == Utility::String::ParseState::Clamped) { // handle value out of bounds ... } else { // handle success ... }
If clamping / overflow doesn't need to be handled, it's enough to check that the function doesn't return ParseState::
Note that in comparison to std::string as trimmed(), with trimmedPrefix() or with trimmedSuffix():
std::int32_t value; if(Utility::String::parseHexadecimal(string.trimmed(), value) != Utility::String::ParseState::Failed) { … }
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: uint8_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 8-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to 0 and max set to 255 and converting the value to a 8-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: int8_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 8-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to -128 and max set to 127 and converting the value to a 8-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: uint16_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 16-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to 0 and max set to 65535 and converting the value to a 16-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: int16_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 16-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to -32768 and max set to 32767 and converting the value to a 16-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: uint32_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 32-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to 0 and max set to a max representable unsigned 32-bit value and converting the value to a 32-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: int32_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 32-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min and max set to a min and max representable signed 32-bit value and converting the value to a 32-bit type.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: uint64_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing an unsigned 64-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min set to 0 and max set to a max representable unsigned 64-bit value.
ParseResult Corrade:: Utility:: String:: parseHexadecimal(Containers:: StringView string,
std:: int64_t& value,
ParseHexadecimalFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a signed 64-bit hexadecimal number.
Equivalent to calling parseHexadecimal(Containers::min and max set to a min and max representable signed 64-bit value.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseFloatFlag value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
Utility:: Debug& Corrade:: Utility:: String:: operator<<(Utility:: Debug& debug,
ParseFloatFlags value) new in Git master
#include <Corrade/Utility/String.h>
Debug output operator.
ParseResult Corrade:: Utility:: String:: parseFloat(Containers:: StringView string,
float& value,
ParseFloatFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
Parse a string containing a floating-point number.
| Parameters | |
|---|---|
| string in | Input string |
| value out | Output value |
| flags in | Flags |
| Returns | Parse state |
If the string is a floating-point numberic value, optionally prepended with a + or - sign unless ParseDecimalFlag::value and returns ParseState::value is set to either positive or negative infinity as appropriate. If the input string is a literal inf or nan, optionally with a sign, it results in ParseState::value set to either infinity or NaN with an appropriate sign. If the string isn't a valid floating-point number, returns ParseState::value left in an unspecified state. Example usage:
float value; Utility::String::ParseResult result = Utility::String::parseFloat(…, value); if(result == Utility::String::ParseState::Failed) { // handle a parsing failure ... } else if(result == Utility::String::ParseState::Clamped) { // handle value out of bounds ... } else { // handle success ... }
If clamping / overflow doesn't need to be handled, it's enough to check that the function doesn't return ParseState::
Note that in comparison to std::string as trimmed(), with trimmedPrefix() or with trimmedSuffix():
float value; if(Utility::String::parseFloat(string.trimmed(), value) != Utility::String::ParseState::Failed) { … }
ParseResult Corrade:: Utility:: String:: parseFloat(Containers:: StringView string,
double& value,
ParseFloatFlags flags = {}) new in Git master
#include <Corrade/Utility/String.h>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Containers:: Optional<Containers:: Array<std:: uint32_t>> Corrade:: Utility:: String:: parseNumberSequence(Containers:: StringView string,
std:: uint32_t min,
std:: uint32_t max) new in Git master
#include <Corrade/Utility/String.h>
Parse a number sequence.
Parses a string containing a sequence of numbers, returning them converted to integers. The numbers can be delimited by commas (,), semicolons (;) or an arbitrary whitespace character. Order in which the numbers were specified is kept in the output including possible duplicates. Empty string results in an empty array returned.
Additionally it's possible to specify a range using the - character, in which case the range will be expanded in the output. The range is inclusive, meaning 3-6 will result in {3, 4, 5, 6} in the output. Ranges where the end is smaller than the start (such as 6-3) will be treated as empty. If the number before the - is omitted, a min is used instead; if the number after the - is omitted, max - 1 is used instead.
If an unrecognized character is encountered, the function prints an error and returns a Containers::min, greater than or equal to max or doesn't fit into 32 bits, it's omitted in the output.
Example usage:
4,3 5;5;17results in{4, 3, 5, 5, 17}12-,3-5,1withmaxset to15results in{12, 13, 14, 3, 4, 5, 1}-3, 13-withminset to0andmaxto15results in{0, 1, 2, 3, 13, 14}- any input with
minset to0andmaxset to0results in an empty output -results in a range frommintomax - 1
std:: string Corrade:: Utility:: String:: fromArray(const char* string)
#include <Corrade/Utility/String.h>
Safely construct string from char array.
If string is nullptr, returns empty string.
nullptr as an empty string on its own
std:: string Corrade:: Utility:: String:: fromArray(const char* string,
std:: size_t length)
#include <Corrade/Utility/String.h>
Safely construct string from char array with explicit length.
If string is nullptr, returns empty string. Otherwise takes also length into account.
nullptr as an empty string on its own
std:: string Corrade:: Utility:: String:: ltrim(std:: string string,
const std:: string& characters)
#include <Corrade/Utility/String.h>
Trim leading characters from string.
| Parameters | |
|---|---|
| string | String to be trimmed |
| characters | Characters which will be trimmed |
Implemented using ltrimInPlace().
std:: string Corrade:: Utility:: String:: ltrim(std:: string string)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Trim trailing characters from string.
| Parameters | |
|---|---|
| string | String to be trimmed |
| characters | Characters which will be trimmed |
Implemented using rtrimInPlace().
std:: string Corrade:: Utility:: String:: rtrim(std:: string string)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
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().
std:: string Corrade:: Utility:: String:: trim(std:: string string)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Trim leading characters from a string, in place.
| Parameters | |
|---|---|
| string | String to be trimmed in place |
| characters | Characters which will be trimmed |
void Corrade:: Utility:: String:: ltrimInPlace(std:: string& string)
#include <Corrade/Utility/String.h>
Trim leading whitespace from a string, in place.
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)
#include <Corrade/Utility/String.h>
Trim trailing characters from a string, in place.
| Parameters | |
|---|---|
| string | String to be trimmed |
| characters | Characters which will be trimmed |
void Corrade:: Utility:: String:: rtrimInPlace(std:: string& string)
#include <Corrade/Utility/String.h>
Trim trailing whitespace from a string, in place.
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)
#include <Corrade/Utility/String.h>
Trim leading and trailing characters from a string, in place.
| Parameters | |
|---|---|
| string | String to be trimmed |
| characters | Characters which will be trimmed |
Equivalent to calling both ltrimInPlace() and rtrimInPlace().
void Corrade:: Utility:: String:: trimInPlace(std:: string& string)
#include <Corrade/Utility/String.h>
Trim leading and trailing whitespace from a string, in place.
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)
#include <Corrade/Utility/String.h>
Split a string on given character.
| Parameters | |
|---|---|
| string | String to split |
| delimiter | Delimiter |
Containers:: Array<Containers:: StringView> Corrade:: Utility:: String:: split(Containers:: StringView string,
char delimiter)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Split a 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)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Split a 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)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Split a string on whitespace 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)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Partition a string.
Equivalent to Python's str.partition(). Splits string at the first occurrence 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)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Right-partition a string.
Equivalent to Python's str.rpartition(). Splits string at the last occurrence 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)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Join strings with given character.
| Parameters | |
|---|---|
| strings | Strings to join |
| delimiter | Delimiter |
std:: string Corrade:: Utility:: String:: join(const std:: vector<std:: string>& strings,
const std:: string& delimiter)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Join strings with given character and remove empty parts.
| Parameters | |
|---|---|
| strings | Strings to join |
| delimiter | Delimiter |
std:: string Corrade:: Utility:: String:: joinWithoutEmptyParts(const std:: vector<std:: string>& strings,
const std:: string& delimiter)
#include <Corrade/Utility/String.h>
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,
const std:: string& prefix)
#include <Corrade/Utility/String.h>
Whether the string has given prefix.
In particular, returns true for empty string only if prefix is empty as well.
bool Corrade:: Utility:: String:: beginsWith(const std:: string& string,
char prefix)
#include <Corrade/Utility/String.h>
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:: viewBeginsWith(Containers:: ArrayView<const char> string,
Containers:: ArrayView<const char> prefix)
#include <Corrade/Utility/String.h>
Whether string view has given prefix.
bool Corrade:: Utility:: String:: viewBeginsWith(Containers:: ArrayView<const char> string,
char prefix)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Whether the string has given suffix.
In particular, returns true for empty string only if suffix is empty as well.
bool Corrade:: Utility:: String:: endsWith(const std:: string& string,
char suffix)
#include <Corrade/Utility/String.h>
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:: viewEndsWith(Containers:: ArrayView<const char> string,
Containers:: ArrayView<const char> suffix)
#include <Corrade/Utility/String.h>
Whether string view has given suffix.
bool Corrade:: Utility:: String:: viewEndsWith(Containers:: ArrayView<const char> string,
char suffix)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Strip given prefix from a string.
Expects that the string actually begins with given prefix.
std:: string Corrade:: Utility:: String:: stripPrefix(std:: string string,
char prefix)
#include <Corrade/Utility/String.h>
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)
#include <Corrade/Utility/String.h>
Strip given suffix from a string.
Expects that the string actually ends with given suffix.
std:: string Corrade:: Utility:: String:: stripSuffix(std:: string string,
char suffix)
#include <Corrade/Utility/String.h>
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.