Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Language
English













SourceForge.net Logo

String

 

class String : public Moveable<String, AString<String0> > 

String is a value class that contains an array of characters (or bytes). It is designed to have fast copy operations. The array of characters is zero terminated. String provides non-mutable access to the array of characters. String can store 8 bit encoded string or an UTF-8 encoded string. For UTF-8 strings, however, String works with raw 8 bit values - there are not automatic conversions performed e.g. in operator[]. If you need to access individual UTF-8 characters, the best practice in most cases is to convert it to WString (and eventually back after processing).

String is also often used to store raw binary data.

WString is similar to String, but it uses 16 bit Ucs2 encoding. String and WString share a number of common functions through the AString interface.

 

 

Constructor Detail

 

String()

Default constructor. Constructs empty String.

 


 

String(const String& s)

Default copy constructor.

 


 

String(const char *s)

Creates a copy of zero terminated string s.

 


 

String(const char *s, int n)

Constructs a string equal to first n characters of string s. Zero characters are included.

 


 

String(const String& s, int n)

Constructs a string equal to first n characters of String s.  Zero characters are included.

 


 

String(const byte *s, int n)

Constructs a string equal to first n bytes of s. Zero characters are included.

 


 

String(const char *s, const char *lim)

Constructs a string equal to first lim - s characters of s. Zero characters are included.

 


 

String(int chr, int count)

Constructs a string consisting of count characters equal to chr. chr can be zero.

 


 

String(StringBuffer& b)

Constructs a string from b. b is emptied by this operation.

 


 

String(const Nuller&)

Constructs empty String. This variant is important to allow assigning Null to String (which is same as assigning the empty String).

 


 

String(const std::string& s)

Constructor to achieve minimal STL compatibility.

 

 

Public Member List

 

void Shrink()

Reduces memory used by string to minimum (size optimization).

 


 

int GetCharCount() const

Returns a number of characters contained in String. This is equal GetCount() if default charset is not UTF-8, but different for UTF-8. It is faster equivalent of ToWString().GetCount().

 


 

WString ToWString() const

Convert String to WString using current default character set.

 


 

const String& ToString() const

Returns *this. Useful because ToString is standard method to convert concrete type to text, used by AsString template (and therefore by operator << as well).

 


 

static String GetVoid()

Returns special Void value. This value is same as empty string, but IsVoid method returns true for it. It can be used in special scenarios where client code needs to distinguish between two empty values (let us say Void is "more empty"...). For example, LoadFile returns Void string if file failed to load, but normal empty string if it is empty.

 


 

bool IsVoid() const

Returns true if String is special value returned by GetVoid.

 


 

bool IsEqual(const String& sconst

Return true if string is equal to s.

 


 

int Compare(const String0& sconst

Lexicographic comparison, return -1 if this string is lower, 0 for equality, 1 if this string is greater. Individual characters are compared as unsigned integer values.

 


 

unsigned GetHashValue() const

Returns the hash value of the string.

 


 

void Cat(int c)

const String& operator+=(char c)

Appends single character c. This operations has constant amortized time (in other words, internal space used by implementation grows exponentially, like with Vector or std::vector). c can be zero.

 


 

void Cat(const char *s, int len)

Appends len characters from string s (s can contain zero characters).

 


 

void Set(int i, int chr)

Replace character at position i with chr.

 


 

void Trim(int pos)

Sets the number of characters (length) to pos.

 


 

const char *Begin() const

Returns a pointer to the first character.

 


 

const char *End() const

Returns a pointer to ending zero.

 


 

void Remove(int pos, int count = 1)

Removes count element starting at position pos.

 


 

void Clear()

Empties the string.

 


 

int GetCount() const

int GetLength() const

Returns the number of characters.

 


 

int GetAlloc() const

Returns the number of allocated characters (maximum string length before it has to grow)

 


 

void Reserve(int r)

Reserves r characters of internal storage for future concatenation operations.

 


 

const String& operator+=(const char *s)

const String& operator+=(const String& s)

Appends a zero terminated string s.

 


 

String& operator=(const String& s)

Assigns another string s. This operations is relatively fast and does not depend on the length of string.

 


 

String& operator=(const char *s)

Assign a zero terminated string s.

 


 

String& operator=(StringBuffer& b)

Assigns the content of StringBuffer. After the operation,b is emptied.

 


 

String& operator<<=(const String& s)

"Deep" assignment. It is equivalent of standard assignment followed by Shrink operation (in other words, internal buffer gets reallocated to the exact size of source).

 


 

operator std::string() const

Conversion for minimal STL compatibility.

 


 

operator const char *() const

const char *operator~() const

Returns Begin().

 


 

int operator[](int iconst

Returns the character at position i.

 

 

 

 

WString

 

class WString : public Moveable<WString, AString<WString0> > 

WString is similar to String, but it uses 16 bit Ucs2 encoding. String and WString share a number of common functions through the AString interface.

 

 

Constructor Detail

 

WString()

Default constructor. Constructs empty WString.

 


 

WString(const WString& s)

Default copy constructor.

 


 

WString(const wchar *s)

Creates a copy of zero terminated string s.

 


 

WString(const char *s)

Creates a copy of zero terminated string s.

 


 

WString(const WString& s, int n)

Constructs a string equal to first n characters of WString s (s can contain zero characters).

 


 

WString(const wchar *s, int n)

Constructs a string equal to first n characters of s (s can contain zero characters).

 


 

WString(const wchar *s, const wchar *lim)

Constructs a string equal to first lim - s characters of s (s can contain zero characters).

 


 

WString(const char *s, int n)

Constructs a string equal to first n characters of zero terminated string s (s can contain zero characters).

 


 

WString(const char *s, const char *lim)

Constructs a string equal to first n characters of zero terminated string s (s can contain zero characters).

 


 

WString(int chr, int count)

Constructs a string consisting of count characters equal to chr. chr can be zero.

 


 

WString(WStringBuffer& b)

Constructs a string from b. b is emptied by this operation.

 


 

WString(const Nuller&)

Constructs empty WString. This variant is important to allow assigning Null to WString (which is same as assigning the empty WString).

 


 

WString(const std::wstring& s)

Constructor to achieve minimal STL compatibility.

 

 

Public Member List

 

void Shrink()

Reduces memory used by string to minimum (size optimization).

 


 

String ToString() const

Converts WString to String using current default character set. Also serves as standard text conversion (for AsString and operator<< templates).

 


 

static WString GetVoid()

Returns special Void value. This value is same as empty string, but IsVoid method returns true for it. It can be used in special scenarios where client code needs to distinguish between two empty values (let us say Void is "more empty"...). For example, LoadFile returns Void string if file failed to load, but normal empty string if it is empty.

 


 

bool IsVoid() const

Returns true if String is special value returned by GetVoid.

 


 

const wchar *Begin() const

Returns a pointer to the first character.

 


 

const wchar *End() const

Returns a pointer to ending zero.

 


 

int GetCount() const

int GetLength() const

Returns the number of characters.

 


 

int GetAlloc() const

Returns the number of allocated characters (maximum string length before it has to grow)

 


 

void Cat(int c)

Appends single character c. This operations has constant amortized time (in other words, internal space used by implementation grows exponentially, like with Vector or std::vector).

 


 

void Cat(const wchar *s, int length)

Appends len characters from string s (s can contain zero characters).

 


 

unsigned GetHashValue() const

Returns the hash value of the string.

 


 

bool IsEqual(const WString& sconst

Return true if string is equal to s.

 


 

int Compare(const WString& sconst

Lexicographic comparison, return -1 if this string is lower, 0 for equality, 1 if this string is greater. Individual characters are compared as unsigned integer values.

 


 

void Remove(int pos, int count = 1)

Removes count element starting at position pos.

 


 

void Insert(int pos, const wchar *s, int count)

Inserts first count characters of s at position pos.

 


 

void Clear()

Empties the string.

 


 

void Set(int pos, int ch)

Replace character at position pos  with ch.

 


 

void Trim(int pos)

Sets the number of characters (length) to pos.

 

 

 

 

AString

 

template <class B>

class AString : public B

A class that implements behavior common to both String and WString.

 

 

Public Member List

 

void Clear()

Clears the content of the string.

 


 

int GetLength() const

Returns the length of the string.

 


 

bool IsEmpty() const

Return true if the length of the string is zero.

 


 

const tchar *End() const

Returns a pointer to the end of the string.

 


 

const tchar *Last() const

Returns a pointer to the last character in the string. If string is empty, returns a pointer to the ending zero.

 


 

const tchar *GetIter(int iconst

Returns a pointer to character index i of the string.

 


 

int operator[](int iconst

Returns the character with index i.

 


 

operator const tchar *() const

const tchar *operator~() const

operator const void *() const

operator const bchar *() const

Same as Begin().

 


 

void Insert(int pos, int c)

void Insert(int pos, const tchar *s, int count)

void Insert(int pos, const String& s)

void Insert(int pos, const char *s)

Inserts item c/s at position pos (count times).

 


 

String Mid(int pos, int lengthconst

Returns a substring that begins from pos and with length chars.

 


 

String Mid(int posconst

Returns a substring that begins from pos.

 


 

String Right(int countconst

Returns a substring with count chars beginning from the ens of the string.

 


 

String Left(int countconst

Returns a substring with count chars beginning from the begin of the string.

 


 

int Find(const tchar *s, int from = 0const

int Find(const String& s, int from = 0const

Returns first position of substring s tested from from position, or -1 if s is not found.

 


 

int FindAfter(const tchar *s, int from = 0const

int FindAfter(const String& s, int from = 0const

Similiar to Find, but if found, returns position after the substring found. In other words, if not found returns -1, if found, returns Find(s, from) + strlen(s).

 


 

void Replace(const String& find, const String& replace)

void Replace(const tchar *find, const tchar *replace)

void Replace(const String& find, const tchar *replace)

void Replace(const tchar *find, const String& replace)

Replaces substring find with replace string for all times find string appears.

 

Last edit by cxl on 04/12/2014. Do you want to contribute?. T++