TGUI
0.8.9
|
Wrapper class to store strings. More...
#include <TGUI/String.hpp>
Public Member Functions | |
int | toInt (int defaultValue=0) const |
Converts the string to an integer. More... | |
unsigned int | toUInt (unsigned int defaultValue=0) const |
Converts the string to an unsigned int. More... | |
float | toFloat (float defaultValue=0) const |
Converts the string to a float. More... | |
String | trim () const |
Returns a string with the whitespace at the start and end of this string removed. More... | |
String | toLower () const |
Converts the ASCII characters in the string to lowercase. More... | |
String | toUpper () const |
Converts the ASCII characters in the string to uppercase. More... | |
Static Public Member Functions | |
template<typename T > | |
static String | fromNumber (T value) |
Construct the string from a number. More... | |
Wrapper class to store strings.
A constructor and conversion operator are provided for sf::String to easily convert between sf::String and tgui::String.
The interface is similar to std::basic_string, but functions accept char, wchar_t, char8_t, char16_t and char32_t. Some extra helper functions are also provided to e.g. convert the string to an integer or float or to lowercase.
Note that when converting to std::string, an UTF-8 encoded string will be returned, even by the asAnsiString function. This is done to be able to use UTF-8 without c++20 support (the toUtf8 function always returns an std::u8string). Similarly, when passing an std::string or const char* to this class, the encoding is assumed to be UTF-8.
Data is stored in UTF-32, so any parameter or operator using a different encoding will have to convert the string internally and may be slightly slower than the variants that use UTF-32.
|
inlinestatic |
Construct the string from a number.
value | Number to convert to string |
float tgui::String::toFloat | ( | float | defaultValue = 0 | ) | const |
Converts the string to a float.
defaultValue | Value to return if conversion fails |
Returns the float value or defaultValue if the string didn't contain an float
int tgui::String::toInt | ( | int | defaultValue = 0 | ) | const |
Converts the string to an integer.
defaultValue | Value to return if conversion fails |
Returns the integer value or defaultValue if the string didn't contain a base 10 integer
String tgui::String::toLower | ( | ) | const |
Converts the ASCII characters in the string to lowercase.
unsigned int tgui::String::toUInt | ( | unsigned int | defaultValue = 0 | ) | const |
Converts the string to an unsigned int.
defaultValue | Value to return if conversion fails |
Returns the unsigned integer value or defaultValue if the string didn't contain a base 10 unsigned integer
String tgui::String::toUpper | ( | ) | const |
Converts the ASCII characters in the string to uppercase.
String tgui::String::trim | ( | ) | const |
Returns a string with the whitespace at the start and end of this string removed.