TGUI  1.6.1
Loading...
Searching...
No Matches

Wrapper class to store strings. More...

#include <TGUI/String.hpp>

Public Types

using iterator = std::u32string::iterator
 
using const_iterator = std::u32string::const_iterator
 
using reverse_iterator = std::u32string::reverse_iterator
 
using const_reverse_iterator = std::u32string::const_reverse_iterator
 
using value_type = char32_t
 
using reference = char32_t&
 
using const_reference = const char32_t&
 

Public Member Functions

bool attemptToInt (int &result) const
 Converts the string to an integer.
 
bool attemptToUInt (unsigned int &result) const
 Converts the string to an unsigned int.
 
bool attemptToFloat (float &result) const
 Converts the string to a float.
 
int toInt (int defaultValue=0) const
 Converts the string to an integer.
 
unsigned int toUInt (unsigned int defaultValue=0) const
 Converts the string to an unsigned int.
 
float toFloat (float defaultValue=0) const
 Converts the string to a float.
 
String trim () const
 Returns a string with the whitespace at the start and end of this string removed.
 
String toLower () const
 Converts the ASCII characters in the string to lowercase.
 
String toUpper () const
 Converts the ASCII characters in the string to uppercase.
 
bool equalIgnoreCase (const String &other) const
 Compares this string to another and checks if they are equal if ASCII letters would have been lowercase.
 
bool startsWith (const String &substring) const
 Checks whether the first part of the string matches the given substring.
 
bool startsWithIgnoreCase (const String &substring) const
 Checks whether the first part of the string matches the given substring, case-insensitive.
 
bool endsWith (const String &substring) const
 Checks whether the last part of the string matches the given substring.
 
bool endsWithIgnoreCase (const String &substring) const
 Checks whether the last part of the string matches the given substring, case-insensitive.
 
Stringreplace (const String &searchFor, const String &replaceWith)
 Replaces all occurrences of a substring with a replacement string.
 
void remove (const String &substring)
 Removes all occurrences of the given substring.
 
std::vector< Stringsplit (const String &delimiter, bool trim=false) const
 Splits the string into multiple substrings given the delimiter that separates them.
 
 String (const std::string &str)
 
 String (const std::wstring &str)
 
 String (const std::u16string &str)
 
 String (const std::u32string &str)
 
 String (std::u32string &&str)
 
 String (char ansiChar)
 
 String (wchar_t wideChar)
 
 String (char16_t utfChar)
 
 String (char32_t utfChar)
 
 String (const char *str)
 
 String (const wchar_t *str)
 
 String (const char16_t *str)
 
 String (const char32_t *str)
 
template<typename T , typename = typename std::enable_if_t<std::is_arithmetic<T>::value, T>>
 String (T number)
 
 String (std::size_t count, char ch)
 
 String (std::size_t count, wchar_t ch)
 
 String (std::size_t count, char16_t ch)
 
 String (std::size_t count, char32_t ch)
 
 String (const std::string &str, std::size_t pos)
 
 String (const std::wstring &str, std::size_t pos)
 
 String (const std::u16string &str, std::size_t pos)
 
 String (const std::u32string &str, std::size_t pos)
 
 String (const std::string &str, std::size_t pos, std::size_t count)
 
 String (const std::wstring &str, std::size_t pos, std::size_t count)
 
 String (const std::u16string &str, std::size_t pos, std::size_t count)
 
 String (const std::u32string &str, std::size_t pos, std::size_t count)
 
 String (const char *str, std::size_t count)
 
 String (const wchar_t *str, std::size_t count)
 
 String (const char16_t *str, std::size_t count)
 
 String (const char32_t *str, std::size_t count)
 
 String (std::initializer_list< char > chars)
 
 String (std::initializer_list< wchar_t > chars)
 
 String (std::initializer_list< char16_t > chars)
 
 String (std::initializer_list< char32_t > chars)
 
 String (std::string::const_iterator first, std::string::const_iterator last)
 
 String (std::wstring::const_iterator first, std::wstring::const_iterator last)
 
 String (std::u16string::const_iterator first, std::u16string::const_iterator last)
 
 String (std::u32string::const_iterator first, std::u32string::const_iterator last)
 
template<typename StringViewType , typename = IsStringViewType<StringViewType>>
 String (const StringViewType &stringView)
 
template<typename StringViewType , typename = IsStringViewType<StringViewType>>
 String (const StringViewType &stringView, std::size_t pos, std::size_t count)
 
 String (const sf::String &str)
 
 operator sf::String () const
 
 operator std::string () const
 
 operator std::wstring () const
 
 operator std::u16string () const
 
 operator const std::u32string & () const
 
 operator StringView () const noexcept
 
std::string toStdString () const
 
std::wstring toWideString () const
 
std::u16string toUtf16 () const
 
const std::u32string & toUtf32 () const
 
Stringassign (std::size_t count, char ch)
 
Stringassign (std::size_t count, wchar_t ch)
 
Stringassign (std::size_t count, char16_t ch)
 
Stringassign (std::size_t count, char32_t ch)
 
Stringassign (StringView sv)
 
Stringassign (const char32_t *str)
 
Stringassign (const std::u32string &str)
 
Stringassign (const String &str)
 
Stringassign (StringView sv, std::size_t pos, std::size_t count=npos)
 
Stringassign (const std::string &str, std::size_t pos, std::size_t count=npos)
 
Stringassign (const std::wstring &str, std::size_t pos, std::size_t count=npos)
 
Stringassign (const std::u16string &str, std::size_t pos, std::size_t count=npos)
 
Stringassign (const std::u32string &str, std::size_t pos, std::size_t count=npos)
 
Stringassign (const String &str, std::size_t pos, std::size_t count=npos)
 
Stringassign (std::u32string &&str)
 
Stringassign (String &&str)
 
Stringassign (const char *str, std::size_t count)
 
Stringassign (const wchar_t *str, std::size_t count)
 
Stringassign (const char16_t *str, std::size_t count)
 
Stringassign (const char32_t *str, std::size_t count)
 
Stringassign (std::initializer_list< char > chars)
 
Stringassign (std::initializer_list< wchar_t > chars)
 
Stringassign (std::initializer_list< char16_t > chars)
 
Stringassign (std::initializer_list< char32_t > chars)
 
Stringassign (std::string::const_iterator first, std::string::const_iterator last)
 
Stringassign (std::wstring::const_iterator first, std::wstring::const_iterator last)
 
Stringassign (std::u16string::const_iterator first, std::u16string::const_iterator last)
 
Stringassign (std::u32string::const_iterator first, std::u32string::const_iterator last)
 
Stringassign (StringView::const_iterator first, StringView::const_iterator last)
 
reference at (std::size_t pos)
 
const_reference at (std::size_t pos) const
 
const_reference operator[] (std::size_t index) const
 
reference operator[] (std::size_t index)
 
reference front ()
 
const_reference front () const
 
reference back ()
 
const_reference back () const
 
const char32_t * data () const noexcept
 
char32_t * data () noexcept
 
const char32_t * c_str () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
bool empty () const noexcept
 
std::size_t size () const noexcept
 
std::size_t length () const noexcept
 
std::size_t max_size () const noexcept
 
void reserve (std::size_t newCap)
 
std::size_t capacity () const noexcept
 
void shrink_to_fit ()
 
void clear () noexcept
 
Stringinsert (std::size_t index, std::size_t count, char ch)
 
Stringinsert (std::size_t index, std::size_t count, wchar_t ch)
 
Stringinsert (std::size_t index, std::size_t count, char16_t ch)
 
Stringinsert (std::size_t index, std::size_t count, char32_t ch)
 
Stringinsert (std::size_t index, StringView sv)
 
Stringinsert (std::size_t index, const char32_t *str)
 
Stringinsert (std::size_t index, const std::u32string &str)
 
Stringinsert (std::size_t index, const String &str)
 
Stringinsert (std::size_t index, StringView sv, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const std::string &str, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const std::wstring &str, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const std::u16string &str, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const std::u32string &str, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const String &str, std::size_t pos, std::size_t count=npos)
 
Stringinsert (std::size_t index, const char *str, std::size_t count)
 
Stringinsert (std::size_t index, const wchar_t *str, std::size_t count)
 
Stringinsert (std::size_t index, const char16_t *str, std::size_t count)
 
Stringinsert (std::size_t index, const char32_t *str, std::size_t count)
 
iterator insert (const_iterator pos, char ch)
 
iterator insert (const_iterator pos, wchar_t ch)
 
iterator insert (const_iterator pos, char16_t ch)
 
iterator insert (const_iterator pos, char32_t ch)
 
iterator insert (const_iterator pos, std::size_t count, char ch)
 
iterator insert (const_iterator pos, std::size_t count, wchar_t ch)
 
iterator insert (const_iterator pos, std::size_t count, char16_t ch)
 
iterator insert (const_iterator pos, std::size_t count, char32_t ch)
 
iterator insert (const_iterator pos, std::initializer_list< char > chars)
 
iterator insert (const_iterator pos, std::initializer_list< wchar_t > chars)
 
iterator insert (const_iterator pos, std::initializer_list< char16_t > chars)
 
iterator insert (const_iterator pos, std::initializer_list< char32_t > chars)
 
iterator insert (const_iterator pos, std::string::const_iterator first, std::string::const_iterator last)
 
iterator insert (const_iterator pos, std::wstring::const_iterator first, std::wstring::const_iterator last)
 
iterator insert (const_iterator pos, std::u16string::const_iterator first, std::u16string::const_iterator last)
 
iterator insert (const_iterator pos, std::u32string::const_iterator first, std::u32string::const_iterator last)
 
iterator insert (const_iterator pos, StringView::const_iterator first, StringView::const_iterator last)
 
Stringerase (std::size_t index=0, std::size_t count=npos)
 
iterator erase (const_iterator position)
 
iterator erase (const_iterator first, const_iterator last)
 
void push_back (char ch)
 
void push_back (wchar_t ch)
 
void push_back (char16_t ch)
 
void push_back (char32_t ch)
 
void pop_back ()
 
Stringappend (std::size_t count, char ch)
 
Stringappend (std::size_t count, wchar_t ch)
 
Stringappend (std::size_t count, char16_t ch)
 
Stringappend (std::size_t count, char32_t ch)
 
Stringappend (StringView sv)
 
Stringappend (const char32_t *str)
 
Stringappend (const std::u32string &str)
 
Stringappend (const String &str)
 
Stringappend (StringView sv, std::size_t pos, std::size_t count=npos)
 
Stringappend (const std::string &str, std::size_t pos, std::size_t count=npos)
 
Stringappend (const std::wstring &str, std::size_t pos, std::size_t count=npos)
 
Stringappend (const std::u16string &str, std::size_t pos, std::size_t count=npos)
 
Stringappend (const std::u32string &str, std::size_t pos, std::size_t count=npos)
 
Stringappend (const String &str, std::size_t pos, std::size_t count=npos)
 
Stringappend (const char *str, std::size_t count)
 
Stringappend (const wchar_t *str, std::size_t count)
 
Stringappend (const char16_t *str, std::size_t count)
 
Stringappend (const char32_t *str, std::size_t count)
 
Stringappend (std::string::const_iterator first, std::string::const_iterator last)
 
Stringappend (std::wstring::const_iterator first, std::wstring::const_iterator last)
 
Stringappend (std::u16string::const_iterator first, std::u16string::const_iterator last)
 
Stringappend (std::u32string::const_iterator first, std::u32string::const_iterator last)
 
Stringappend (StringView::const_iterator first, StringView::const_iterator last)
 
Stringappend (std::initializer_list< char > chars)
 
Stringappend (std::initializer_list< wchar_t > chars)
 
Stringappend (std::initializer_list< char16_t > chars)
 
Stringappend (std::initializer_list< char32_t > chars)
 
Stringoperator+= (const String &str)
 
int compare (StringView sv) const noexcept
 
int compare (const char32_t *s) const
 
int compare (const std::u32string &str) const noexcept
 
int compare (const String &str) const noexcept
 
int compare (std::size_t pos1, std::size_t count1, StringView sv) const
 
int compare (std::size_t pos1, std::size_t count1, const char32_t *s) const
 
int compare (std::size_t pos1, std::size_t count1, const std::u32string &str) const
 
int compare (std::size_t pos1, std::size_t count1, const String &str) const
 
int compare (std::size_t pos1, std::size_t count1, StringView sv, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const std::string &str, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const std::wstring &str, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const std::u16string &str, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const std::u32string &str, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const String &str, std::size_t pos2, std::size_t count2=npos) const
 
int compare (std::size_t pos1, std::size_t count1, const char *s, std::size_t count2) const
 
int compare (std::size_t pos1, std::size_t count1, const wchar_t *s, std::size_t count2) const
 
int compare (std::size_t pos1, std::size_t count1, const char16_t *s, std::size_t count2) const
 
int compare (std::size_t pos1, std::size_t count1, const char32_t *s, std::size_t count2) const
 
Stringreplace (std::size_t pos, std::size_t count, StringView sv)
 
Stringreplace (std::size_t pos, std::size_t count, const char32_t *cstr)
 
Stringreplace (std::size_t pos, std::size_t count, const std::u32string &str)
 
Stringreplace (std::size_t pos, std::size_t count, const String &str)
 
Stringreplace (const_iterator first, const_iterator last, StringView sv)
 
Stringreplace (const_iterator first, const_iterator last, const char32_t *cstr)
 
Stringreplace (const_iterator first, const_iterator last, const std::u32string &str)
 
Stringreplace (const_iterator first, const_iterator last, const String &str)
 
Stringreplace (std::size_t pos, std::size_t count, StringView sv, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (std::size_t pos, std::size_t count, const std::string &str, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (std::size_t pos, std::size_t count, const std::wstring &str, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (std::size_t pos, std::size_t count, const std::u16string &str, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (std::size_t pos, std::size_t count, const std::u32string &str, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (std::size_t pos, std::size_t count, const String &str, std::size_t pos2, std::size_t count2=npos)
 
Stringreplace (const_iterator first, const_iterator last, std::string::const_iterator first2, std::string::const_iterator last2)
 
Stringreplace (const_iterator first, const_iterator last, std::wstring::const_iterator first2, std::wstring::const_iterator last2)
 
Stringreplace (const_iterator first, const_iterator last, std::u16string::const_iterator first2, std::u16string::const_iterator last2)
 
Stringreplace (const_iterator first, const_iterator last, std::u32string::const_iterator first2, std::u32string::const_iterator last2)
 
Stringreplace (const_iterator first, const_iterator last, StringView::const_iterator first2, StringView::const_iterator last2)
 
Stringreplace (std::size_t pos, std::size_t count, const char *cstr, std::size_t count2)
 
Stringreplace (std::size_t pos, std::size_t count, const wchar_t *cstr, std::size_t count2)
 
Stringreplace (std::size_t pos, std::size_t count, const char16_t *cstr, std::size_t count2)
 
Stringreplace (std::size_t pos, std::size_t count, const char32_t *cstr, std::size_t count2)
 
Stringreplace (const_iterator first, const_iterator last, const char *cstr, std::size_t count2)
 
Stringreplace (const_iterator first, const_iterator last, const wchar_t *cstr, std::size_t count2)
 
Stringreplace (const_iterator first, const_iterator last, const char16_t *cstr, std::size_t count2)
 
Stringreplace (const_iterator first, const_iterator last, const char32_t *cstr, std::size_t count2)
 
Stringreplace (std::size_t pos, std::size_t count, std::size_t count2, char ch)
 
Stringreplace (std::size_t pos, std::size_t count, std::size_t count2, wchar_t ch)
 
Stringreplace (std::size_t pos, std::size_t count, std::size_t count2, char16_t ch)
 
Stringreplace (std::size_t pos, std::size_t count, std::size_t count2, char32_t ch)
 
Stringreplace (const_iterator first, const_iterator last, std::size_t count2, char ch)
 
Stringreplace (const_iterator first, const_iterator last, std::size_t count2, wchar_t ch)
 
Stringreplace (const_iterator first, const_iterator last, std::size_t count2, char16_t ch)
 
Stringreplace (const_iterator first, const_iterator last, std::size_t count2, char32_t ch)
 
Stringreplace (const_iterator first, const_iterator last, std::initializer_list< char > chars)
 
Stringreplace (const_iterator first, const_iterator last, std::initializer_list< wchar_t > chars)
 
Stringreplace (const_iterator first, const_iterator last, std::initializer_list< char16_t > chars)
 
Stringreplace (const_iterator first, const_iterator last, std::initializer_list< char32_t > chars)
 
String substr (std::size_t pos=0, std::size_t count=npos) const
 
std::size_t copy (char32_t *dest, std::size_t count, std::size_t pos=0) const
 
void resize (std::size_t count)
 
void resize (std::size_t count, char ch)
 
void resize (std::size_t count, wchar_t ch)
 
void resize (std::size_t count, char16_t ch)
 
void resize (std::size_t count, char32_t ch)
 
void swap (String &other)
 
bool contains (char c) const noexcept
 
bool contains (wchar_t c) const noexcept
 
bool contains (char16_t c) const noexcept
 
bool contains (char32_t c) const noexcept
 
bool contains (StringView sv) const noexcept
 
bool contains (const char32_t *s) const
 
bool contains (const std::u32string &s) const
 
bool contains (const String &s) const
 
std::size_t find (StringView sv, std::size_t pos=0) const noexcept
 
std::size_t find (const char32_t *s, std::size_t pos=0) const
 
std::size_t find (const std::u32string &str, std::size_t pos=0) const noexcept
 
std::size_t find (const String &str, std::size_t pos=0) const noexcept
 
std::size_t find (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t find (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find (char ch, std::size_t pos=0) const noexcept
 
std::size_t find (wchar_t ch, std::size_t pos=0) const noexcept
 
std::size_t find (char16_t ch, std::size_t pos=0) const noexcept
 
std::size_t find (char32_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (StringView sv, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (const char32_t *s, std::size_t pos=0) const
 
std::size_t find_first_of (const std::u32string &str, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (const String &str, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_of (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_of (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_of (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_of (char ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (wchar_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (char16_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_of (char32_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (StringView sv, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (const char32_t *s, std::size_t pos=0) const
 
std::size_t find_first_not_of (const std::u32string &str, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (const String &str, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_not_of (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_not_of (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_not_of (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_first_not_of (char ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (wchar_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (char16_t ch, std::size_t pos=0) const noexcept
 
std::size_t find_first_not_of (char32_t ch, std::size_t pos=0) const noexcept
 
std::size_t rfind (StringView sv, std::size_t pos=npos) const noexcept
 
std::size_t rfind (const char32_t *s, std::size_t pos=npos) const
 
std::size_t rfind (const std::u32string &str, std::size_t pos=npos) const noexcept
 
std::size_t rfind (const String &str, std::size_t pos=npos) const noexcept
 
std::size_t rfind (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t rfind (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t rfind (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t rfind (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t rfind (char ch, std::size_t pos=npos) const noexcept
 
std::size_t rfind (wchar_t ch, std::size_t pos=npos) const noexcept
 
std::size_t rfind (char16_t ch, std::size_t pos=npos) const noexcept
 
std::size_t rfind (char32_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (StringView sv, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (const char32_t *s, std::size_t pos=npos) const
 
std::size_t find_last_of (const std::u32string &str, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (const String &str, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_of (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_of (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_of (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_of (char ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (wchar_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (char16_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_of (char32_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (StringView sv, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (const char32_t *s, std::size_t pos=npos) const
 
std::size_t find_last_not_of (const std::u32string &str, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (const String &str, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (const char *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_not_of (const wchar_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_not_of (const char16_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_not_of (const char32_t *s, std::size_t pos, std::size_t count) const
 
std::size_t find_last_not_of (char ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (wchar_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (char16_t ch, std::size_t pos=npos) const noexcept
 
std::size_t find_last_not_of (char32_t ch, std::size_t pos=npos) const noexcept
 
bool starts_with (StringView sv) const noexcept
 
bool starts_with (const char32_t *s) const
 
bool starts_with (const std::u32string &s) const
 
bool starts_with (const String &s) const
 
bool starts_with (char ch) const noexcept
 
bool starts_with (wchar_t ch) const noexcept
 
bool starts_with (char16_t ch) const noexcept
 
bool starts_with (char32_t ch) const noexcept
 
bool ends_with (StringView sv) const noexcept
 
bool ends_with (const char32_t *s) const
 
bool ends_with (const std::u32string &s) const
 
bool ends_with (const String &s) const
 
bool ends_with (char ch) const noexcept
 
bool ends_with (wchar_t ch) const noexcept
 
bool ends_with (char16_t ch) const noexcept
 
bool ends_with (char32_t ch) const noexcept
 
std::size_t count (const char ch, const std::size_t pos=0) const noexcept
 
std::size_t count (const wchar_t ch, const std::size_t pos=0) const noexcept
 
std::size_t count (const char16_t ch, const std::size_t pos=0) const noexcept
 
std::size_t count (const char32_t ch, const std::size_t pos=0) const noexcept
 

Static Public Member Functions

static String join (const std::vector< String > &segments, const String &separator)
 Joins multiple string segments into a single string.
 
template<typename T >
static String fromNumber (T value)
 Construct the string from a number.
 
template<typename T >
static String fromNumberRounded (T value, unsigned int decimals)
 Construct the string from a floating point number, keeping only a certain amount of decimals behind the comma.
 

Static Public Attributes

static constexpr auto npos = std::u32string_view::npos
 

Friends

bool operator== (const String &left, StringView right)
 
bool operator== (const String &left, const char32_t *right)
 
bool operator== (const String &left, const std::u32string &right)
 
bool operator== (const String &left, const String &right)
 
bool operator!= (const String &left, StringView right)
 
bool operator!= (const String &left, const char32_t *right)
 
bool operator!= (const String &left, const std::u32string &right)
 
bool operator!= (const String &left, const String &right)
 
bool operator< (const String &left, StringView right)
 
bool operator< (const String &left, const char32_t *right)
 
bool operator< (const String &left, const std::u32string &right)
 
bool operator< (const String &left, const String &right)
 
bool operator<= (const String &left, StringView right)
 
bool operator<= (const String &left, const char32_t *right)
 
bool operator<= (const String &left, const std::u32string &right)
 
bool operator<= (const String &left, const String &right)
 
bool operator> (const String &left, StringView right)
 
bool operator> (const String &left, const char32_t *right)
 
bool operator> (const String &left, const std::u32string &right)
 
bool operator> (const String &left, const String &right)
 
bool operator>= (const String &left, StringView right)
 
bool operator>= (const String &left, const char32_t *right)
 
bool operator>= (const String &left, const std::u32string &right)
 
bool operator>= (const String &left, const String &right)
 
String operator+ (const String &left, const String &right)
 
String operator+ (const String &left, String &&right)
 
String operator+ (String &&left, const String &right)
 
String operator+ (String &&left, String &&right)
 

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

◆ attemptToFloat()

bool tgui::String::attemptToFloat ( float & result) const
nodiscard

Converts the string to a float.

Parameters
resultFloat value if the string contains a float. Unmodified if string is invalid.
Returns
Returns whether the string was valid and a value has been placed into the reference parameter.

◆ attemptToInt()

bool tgui::String::attemptToInt ( int & result) const
nodiscard

Converts the string to an integer.

Parameters
resultInteger value if the string contains a base 10 integer. Unmodified if string is invalid.
Returns
Returns whether the string was valid and a value has been placed into the reference parameter.

◆ attemptToUInt()

bool tgui::String::attemptToUInt ( unsigned int & result) const
nodiscard

Converts the string to an unsigned int.

Parameters
resultUnsigned integer value if the string contains a base 10 unsigned int. Unmodified if string is invalid.
Returns
Returns whether the string was valid and a value has been placed into the reference parameter.

◆ endsWith()

bool tgui::String::endsWith ( const String & substring) const
nodiscard

Checks whether the last part of the string matches the given substring.

Parameters
substringCharacters to compare against the final part of the string
Returns
Does the back of the string match the given substring?
Deprecated
Replaced by ends_with in TGUI 1.0

◆ endsWithIgnoreCase()

bool tgui::String::endsWithIgnoreCase ( const String & substring) const
nodiscard

Checks whether the last part of the string matches the given substring, case-insensitive.

Parameters
substringCharacters to compare against the final part of the string
Returns
Does the back of the string match the given substring if we ignore the case?

◆ equalIgnoreCase()

bool tgui::String::equalIgnoreCase ( const String & other) const
nodiscard

Compares this string to another and checks if they are equal if ASCII letters would have been lowercase.

Parameters
otherThe other string to compare this one with
Returns
Are the strings equal except for the case of ASCII letters?

◆ fromNumber()

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

Construct the string from a number.

Parameters
valueNumber to convert to string
Returns
String representing given number

◆ fromNumberRounded()

template<typename T >
static String tgui::String::fromNumberRounded ( T value,
unsigned int decimals )
inlinestaticnodiscard

Construct the string from a floating point number, keeping only a certain amount of decimals behind the comma.

Parameters
valueNumber to convert to string
decimalsDigits to keep behind the comma
Returns
String representing given number, rounded to the given decimals

◆ join()

static String tgui::String::join ( const std::vector< String > & segments,
const String & separator )
staticnodiscard

Joins multiple string segments into a single string.

Parameters
segmentsSubstrings that need to concatenated behind each other (with optional separators inbetween)
separatorCharacter that separates the substrings

◆ remove()

void tgui::String::remove ( const String & substring)

Removes all occurrences of the given substring.

Parameters
substringThe value to search for and which should be removed

◆ replace()

String & tgui::String::replace ( const String & searchFor,
const String & replaceWith )

Replaces all occurrences of a substring with a replacement string.

Parameters
searchForThe value being searched for
replaceWithThe value that replaces found searchFor values
Returns
Reference to this object.

◆ split()

std::vector< String > tgui::String::split ( const String & delimiter,
bool trim = false ) const
nodiscard

Splits the string into multiple substrings given the delimiter that separates them.

Parameters
delimiterString that separates the substrings
trimShould whitespace be removed at the start and end of each part?

◆ startsWith()

bool tgui::String::startsWith ( const String & substring) const
nodiscard

Checks whether the first part of the string matches the given substring.

Parameters
substringCharacters to compare against the first part of the string
Returns
Does the first part of the string match the given substring?
Deprecated
Replaced by starts_with in TGUI 1.0

◆ startsWithIgnoreCase()

bool tgui::String::startsWithIgnoreCase ( const String & substring) const
nodiscard

Checks whether the first part of the string matches the given substring, case-insensitive.

Parameters
substringCharacters to compare against the first part of the string
Returns
Does the first part of the string match the given substring if we ignore the case?

◆ toFloat()

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

Converts the string to a float.

Parameters
defaultValueValue to return if conversion fails
Returns
Returns the float value or defaultValue if the string didn't contain an float

◆ toInt()

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

Converts the string to an integer.

Parameters
defaultValueValue to return if conversion fails
Returns
Returns the integer value or defaultValue if the string didn't contain a base 10 integer

◆ toLower()

String tgui::String::toLower ( ) const
nodiscard

Converts the ASCII characters in the string to lowercase.

Returns
Lowercase string

◆ toUInt()

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

Converts the string to an unsigned int.

Parameters
defaultValueValue to return if conversion fails
Returns
Returns the unsigned integer value or defaultValue if the string didn't contain a base 10 unsigned integer

◆ toUpper()

String tgui::String::toUpper ( ) const
nodiscard

Converts the ASCII characters in the string to uppercase.

Returns
Uppercase string

◆ trim()

String tgui::String::trim ( ) const
nodiscard

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: