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...
 

Detailed Description

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.

Member Function Documentation

◆ fromNumber()

template<typename T >
static String tgui::String::fromNumber ( value)
inlinestatic

Construct the string from a number.

Parameters
valueNumber to convert to string
Returns
String representing given number

◆ toFloat()

float tgui::String::toFloat ( float  defaultValue = 0) const

Converts the string to a float.

Parameters
defaultValueValue to return if conversion fails

Returns the float value or defaultValue if the string didn't contain an float

◆ toInt()

int tgui::String::toInt ( int  defaultValue = 0) const

Converts the string to an integer.

Parameters
defaultValueValue to return if conversion fails

Returns the integer value or defaultValue if the string didn't contain a base 10 integer

◆ toLower()

String tgui::String::toLower ( ) const

Converts the ASCII characters in the string to lowercase.

Returns
Lowercase string

◆ toUInt()

unsigned int tgui::String::toUInt ( unsigned int  defaultValue = 0) const

Converts the string to an unsigned int.

Parameters
defaultValueValue to return if conversion fails

Returns the unsigned integer value or defaultValue if the string didn't contain a base 10 unsigned integer

◆ toUpper()

String tgui::String::toUpper ( ) const

Converts the ASCII characters in the string to uppercase.

Returns
Uppercase string

◆ trim()

String tgui::String::trim ( ) const

Returns a string with the whitespace at the start and end of this string removed.

Returns
Trimmed string

The documentation for this class was generated from the following file: