String class. More...

#include <Urho3D/Container/Str.h>

Collaboration diagram for Urho3D::String:
[legend]

Public Types

typedef RandomAccessIterator
< char > 
Iterator
 
typedef
RandomAccessConstIterator
< char > 
ConstIterator
 

Public Member Functions

 String ()
 Construct empty.
 
 String (const String &str)
 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, unsigned 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, unsigned length)
 Construct from a character and fill length.
 
template<class T >
 String (const T &value)
 Construct from a convertable value.
 
 ~String ()
 Destruct.
 
Stringoperator= (const String &rhs)
 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 >
String operator+= (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[] (unsigned index)
 Return char at index.
 
const char & operator[] (unsigned index) const
 Return const char at index.
 
char & At (unsigned index)
 Return char at index.
 
const char & At (unsigned 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 (unsigned pos, unsigned length, const String &replaceWith)
 Replace a substring.
 
void Replace (unsigned pos, unsigned 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, unsigned length)
 Append characters.
 
void Insert (unsigned pos, const String &str)
 Insert a string.
 
void Insert (unsigned 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 (unsigned pos, unsigned 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 (unsigned newLength)
 Resize the string.
 
void Reserve (unsigned newCapacity)
 Set new capacity.
 
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 (unsigned pos) const
 Return a substring from position to end.
 
String Substring (unsigned pos, unsigned 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.
 
unsigned Find (const String &str, unsigned startPos=0, bool caseSensitive=true) const
 Return index to the first occurrence of a string, or NPOS if not found.
 
unsigned Find (char c, unsigned startPos=0, bool caseSensitive=true) const
 Return index to the first occurrence of a character, or NPOS if not found.
 
unsigned FindLast (const String &str, unsigned startPos=NPOS, bool caseSensitive=true) const
 Return index to the last occurrence of a string, or NPOS if not found.
 
unsigned FindLast (char c, unsigned 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.
 
const char * CString () const
 Return the C string.
 
unsigned Length () const
 Return length.
 
unsigned 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.
 
unsigned LengthUTF8 () const
 Calculate number of characters in UTF8 content.
 
unsigned ByteOffsetUTF8 (unsigned index) const
 Return byte offset to char in UTF8 content.
 
unsigned NextUTF8Char (unsigned &byteOffset) const
 Return next Unicode character from UTF8 content and increase byte offset.
 
unsigned AtUTF8 (unsigned index) const
 Return Unicode character at index from UTF8 content.
 
void ReplaceUTF8 (unsigned index, unsigned unicodeChar)
 Replace Unicode character at index from UTF8 content.
 
StringAppendUTF8 (unsigned unicodeChar)
 Append Unicode character at the end as UTF8.
 
String SubstringUTF8 (unsigned pos) const
 Return a UTF8 substring from position to end.
 
String SubstringUTF8 (unsigned pos, unsigned length) const
 Return a UTF8 substring with length from position.
 
unsigned 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.
 

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, unsigned unicodeChar)
 Encode Unicode character to UTF8. Pointer will be incremented.
 
static unsigned DecodeUTF8 (const char *&src)
 Decode Unicode character from UTF8. Pointer will be incremented.
 
static unsigned CStringLength (const char *str)
 Return length of a C string.
 
static int Compare (const char *str1, const char *str2, bool caseSensitive)
 Compare two C strings.
 

Static Public Attributes

static const unsigned NPOS = 0xffffffff
 Position for "not found.".
 
static const unsigned MIN_CAPACITY = 8
 Initial dynamic allocation size.
 
static const String EMPTY
 Empty string.
 

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

unsigned length_
 String length.
 
unsigned capacity_
 Capacity, zero if buffer not allocated.
 
char * buffer_
 String buffer, null if not allocated.
 

Static Private Attributes

static char endZero = 0
 End zero for empty strings.
 

Detailed Description

String class.


The documentation for this class was generated from the following files:
  • Source/Urho3D/Container/Str.h
  • Source/Urho3D/Container/Str.cpp