Urho3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Urho3D::String Class Reference

String class. More...

#include </home/runner/work/urho3d-doxygen.github.io/urho3d-doxygen.github.io/urho3d_repo/Source/Urho3D/Container/Str.h>

Classes

struct  LongString
 
struct  ShortString
 

Public Types

using Iterator = RandomAccessIterator< char >
 
using ConstIterator = RandomAccessConstIterator< char >
 

Public Member Functions

 String () noexcept
 Construct empty.
 
 String (const String &str)
 Construct from another string.
 
 String (String &&str) noexcept
 Move-construct from another string.
 
 String (const char *str)
 Construct from a C string.
 
 String (char *str)
 Construct from a C string.
 
 String (const char *str, i32 length)
 Construct from a char array and length.
 
 String (const wchar_t *str)
 Construct from a null-terminated wide character array.
 
 String (wchar_t *str)
 Construct from a null-terminated wide character array.
 
 String (const WString &str)
 Construct from a wide character string.
 
 String (int value)
 Construct from an integer.
 
 String (short value)
 Construct from a short integer.
 
 String (long value)
 Construct from a long integer.
 
 String (long long value)
 Construct from a long long integer.
 
 String (unsigned value)
 Construct from an unsigned integer.
 
 String (unsigned short value)
 Construct from an unsigned short integer.
 
 String (unsigned long value)
 Construct from an unsigned long integer.
 
 String (unsigned long long value)
 Construct from an unsigned long long integer.
 
 String (float value)
 Construct from a float.
 
 String (double value)
 Construct from a double.
 
 String (bool value)
 Construct from a bool.
 
 String (char value)
 Construct from a character.
 
 String (char value, i32 length)
 Construct from a character and fill length.
 
template<class T >
 String (const T &value)
 Construct from a convertible value.
 
 ~String ()
 Destruct.
 
Stringoperator= (const String &rhs)
 Assign a string.
 
Stringoperator= (String &&rhs) noexcept
 Move-assign a string.
 
Stringoperator= (const char *rhs)
 Assign a C string.
 
Stringoperator+= (const String &rhs)
 Add-assign a string.
 
Stringoperator+= (const char *rhs)
 Add-assign a C string.
 
Stringoperator+= (char rhs)
 Add-assign a character.
 
Stringoperator+= (int rhs)
 Add-assign (concatenate as string) an integer.
 
Stringoperator+= (short rhs)
 Add-assign (concatenate as string) a short integer.
 
Stringoperator+= (long rhs)
 Add-assign (concatenate as string) a long integer.
 
Stringoperator+= (long long rhs)
 Add-assign (concatenate as string) a long long integer.
 
Stringoperator+= (unsigned rhs)
 Add-assign (concatenate as string) an unsigned integer.
 
Stringoperator+= (unsigned short rhs)
 Add-assign (concatenate as string) a short unsigned integer.
 
Stringoperator+= (unsigned long rhs)
 Add-assign (concatenate as string) a long unsigned integer.
 
Stringoperator+= (unsigned long long rhs)
 Add-assign (concatenate as string) a long long unsigned integer.
 
Stringoperator+= (float rhs)
 Add-assign (concatenate as string) a float.
 
Stringoperator+= (bool rhs)
 Add-assign (concatenate as string) a bool.
 
template<class T >
Stringoperator+= (const T &rhs)
 Add-assign (concatenate as string) an arbitrary type.
 
String operator+ (const String &rhs) const
 Add a string.
 
String operator+ (const char *rhs) const
 Add a C string.
 
bool operator== (const String &rhs) const
 Test for equality with another string.
 
bool operator!= (const String &rhs) const
 Test for inequality with another string.
 
bool operator< (const String &rhs) const
 Test if string is less than another string.
 
bool operator> (const String &rhs) const
 Test if string is greater than another string.
 
bool operator== (const char *rhs) const
 Test for equality with a C string.
 
bool operator!= (const char *rhs) const
 Test for inequality with a C string.
 
bool operator< (const char *rhs) const
 Test if string is less than a C string.
 
bool operator> (const char *rhs) const
 Test if string is greater than a C string.
 
char & operator[] (i32 index)
 Return char at index.
 
const char & operator[] (i32 index) const
 Return const char at index.
 
char & At (i32 index)
 Return char at index.
 
const char & At (i32 index) const
 Return const char at index.
 
void Replace (char replaceThis, char replaceWith, bool caseSensitive=true)
 Replace all occurrences of a character.
 
void Replace (const String &replaceThis, const String &replaceWith, bool caseSensitive=true)
 Replace all occurrences of a string.
 
void Replace (i32 pos, i32 length, const String &replaceWith)
 Replace a substring.
 
void Replace (i32 pos, i32 length, const char *replaceWith)
 Replace a substring with a C string.
 
Iterator Replace (const Iterator &start, const Iterator &end, const String &replaceWith)
 Replace a substring by iterators.
 
String Replaced (char replaceThis, char replaceWith, bool caseSensitive=true) const
 Return a string with all occurrences of a character replaced.
 
String Replaced (const String &replaceThis, const String &replaceWith, bool caseSensitive=true) const
 Return a string with all occurrences of a string replaced.
 
StringAppend (const String &str)
 Append a string.
 
StringAppend (const char *str)
 Append a C string.
 
StringAppend (char c)
 Append a character.
 
StringAppend (const char *str, i32 length)
 Append characters.
 
void Insert (i32 pos, const String &str)
 Insert a string.
 
void Insert (i32 pos, char c)
 Insert a character.
 
Iterator Insert (const Iterator &dest, const String &str)
 Insert a string by iterator.
 
Iterator Insert (const Iterator &dest, const Iterator &start, const Iterator &end)
 Insert a string partially by iterators.
 
Iterator Insert (const Iterator &dest, char c)
 Insert a character by iterator.
 
void Erase (i32 pos, i32 length=1)
 Erase a substring.
 
Iterator Erase (const Iterator &it)
 Erase a character by iterator.
 
Iterator Erase (const Iterator &start, const Iterator &end)
 Erase a substring by iterators.
 
void Resize (i32 newLength)
 Resize the string. Can increase capacity, but never decrease.
 
void Reserve (i32 newCapacity)
 Set new capacity. New capacity may differ from requested.
 
void Compact ()
 Reallocate so that no extra memory is used.
 
void Clear ()
 Clear the string.
 
void Swap (String &str)
 Swap with another string.
 
Iterator Begin ()
 Return iterator to the beginning.
 
ConstIterator Begin () const
 Return const iterator to the beginning.
 
Iterator End ()
 Return iterator to the end.
 
ConstIterator End () const
 Return const iterator to the end.
 
char Front () const
 Return first char, or 0 if empty.
 
char Back () const
 Return last char, or 0 if empty.
 
String Substring (i32 pos) const
 Return a substring from position to end.
 
String Substring (i32 pos, i32 length) const
 Return a substring with length from position.
 
String Trimmed () const
 Return string with whitespace trimmed from the beginning and the end.
 
String ToUpper () const
 Return string in uppercase.
 
String ToLower () const
 Return string in lowercase.
 
Vector< StringSplit (char separator, bool keepEmptyStrings=false) const
 Return substrings split by a separator char. By default don't return empty strings.
 
void Join (const Vector< String > &subStrings, const String &glue)
 Join substrings with a 'glue' string.
 
i32 Find (const String &str, i32 startPos=0, bool caseSensitive=true) const
 Return index to the first occurrence of a string, or NPOS if not found.
 
i32 Find (char c, i32 startPos=0, bool caseSensitive=true) const
 Return index to the first occurrence of a character, or NPOS if not found.
 
i32 FindLast (const String &str, i32 startPos=NPOS, bool caseSensitive=true) const
 Return index to the last occurrence of a string, or NPOS if not found.
 
i32 FindLast (char c, i32 startPos=NPOS, bool caseSensitive=true) const
 Return index to the last occurrence of a character, or NPOS if not found.
 
bool StartsWith (const String &str, bool caseSensitive=true) const
 Return whether starts with a string.
 
bool EndsWith (const String &str, bool caseSensitive=true) const
 Return whether ends with a string.
 
char * GetBuffer ()
 Return pointer to buffer.
 
const char * GetBuffer () const
 Return pointer to buffer.
 
const char * CString () const
 Return the C string.
 
i32 Length () const
 Return length.
 
i32 Capacity () const
 Return buffer capacity.
 
bool Empty () const
 Return whether the string is empty.
 
int Compare (const String &str, bool caseSensitive=true) const
 Return comparison result with a string.
 
int Compare (const char *str, bool caseSensitive=true) const
 Return comparison result with a C string.
 
bool Contains (const String &str, bool caseSensitive=true) const
 Return whether contains a specific occurrence of a string.
 
bool Contains (char c, bool caseSensitive=true) const
 Return whether contains a specific character.
 
void SetUTF8FromLatin1 (const char *str)
 Construct UTF8 content from Latin1.
 
void SetUTF8FromWChar (const wchar_t *str)
 Construct UTF8 content from wide characters.
 
i32 LengthUTF8 () const
 Calculate number of characters in UTF8 content.
 
i32 ByteOffsetUTF8 (i32 index) const
 Return byte offset to char in UTF8 content.
 
c32 NextUTF8Char (i32 &byteOffset) const
 Return next Unicode character from UTF8 content and increase byte offset.
 
c32 AtUTF8 (i32 index) const
 Return Unicode character at index from UTF8 content.
 
void ReplaceUTF8 (i32 index, c32 unicodeChar)
 Replace Unicode character at index from UTF8 content.
 
StringAppendUTF8 (c32 unicodeChar)
 Append Unicode character at the end as UTF8.
 
String SubstringUTF8 (i32 pos) const
 Return a UTF8 substring from position to end.
 
String SubstringUTF8 (i32 pos, i32 length) const
 Return a UTF8 substring with length from position.
 
hash32 ToHash () const
 Return hash value for HashSet & HashMap.
 
StringAppendWithFormat (const char *formatString,...)
 Append to string using formatting.
 
StringAppendWithFormatArgs (const char *formatString, va_list args)
 Append to string using variable arguments.
 
bool IsShort () const
 Is the string stored on the stack?
 

Static Public Member Functions

static Vector< StringSplit (const char *str, char separator, bool keepEmptyStrings=false)
 Return substrings split by a separator char. By default don't return empty strings.
 
static String Joined (const Vector< String > &subStrings, const String &glue)
 Return a string by joining substrings with a 'glue' string.
 
static void EncodeUTF8 (char *&dest, c32 unicodeChar)
 Encode Unicode character to UTF8. Pointer will be incremented.
 
static c32 DecodeUTF8 (const char *&src)
 Decode Unicode character from UTF8. Pointer will be incremented.
 
static i32 CStringLength (const char *str)
 Return length of a C string.
 
static int Compare (const char *lhs, const char *rhs, bool caseSensitive)
 Compare two C strings.
 

Static Public Attributes

static constexpr i32 NPOS = -1
 Position for "not found".
 
static const String EMPTY
 Empty string.
 

Private Member Functions

i32 GetShortStringLength () const
 
void SetShortStringLength (u8 value)
 
void MoveRange (i32 dest, i32 src, i32 count)
 Move a range of characters within the string.
 
void Replace (i32 pos, i32 length, const char *srcStart, i32 srcLength)
 Replace a substring with another substring.
 

Static Private Member Functions

static void CopyChars (char *dest, const char *src, i32 count)
 Copy chars from one buffer to another.
 

Private Attributes

union {
   LongString   longString_
 
   ShortString   shortString_
 
data_
 

Static Private Attributes

static constexpr i32 SHORT_STRING_CAPACITY = sizeof(LongString) - 1
 11 bytes on 32-bit platform, 15 bytes on 64-bit platform
 
static constexpr u8 SSO_MASK = 0b10000000u
 MSB of the last byte is used as a flag.
 
static constexpr u8 INVERTED_SSO_MASK = static_cast<u8>(~SSO_MASK)
 

Detailed Description

String class.


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