CEGUI::String Class Reference

String class used within the GUI system. More...

List of all members.

Public Types

typedef utf32 value_type
 Basic 'code point' type used for String (utf32).
typedef size_t size_type
 Unsigned type used for size values and indices.
typedef ptrdiff_t difference_type
 Signed type used for differences.
typedef utf32 & reference
 Type used for utf32 code point references.
typedef const utf32 & const_reference
 Type used for constant utf32 code point references.
typedef utf32 * pointer
 Type used for utf32 code point pointers.
typedef const utf32 * const_pointer
 Type used for constant utf32 code point pointers.
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
 Constant reverse iterator class for String objects.
typedef std::reverse_iterator
< iterator
reverse_iterator
 Reverse iterator class for String objects.

Public Member Functions

 String (void)
 Constructs an empty string.
 ~String (void)
 Destructor for String objects.
 String (const String &str)
 Copy constructor - Creates a new string with the same value as str.
 String (const String &str, size_type str_idx, size_type str_num=npos)
 Constructs a new string initialised with code points from another String object.
 String (const std::string &std_str)
 Constructs a new string and initialises it using the std::string std_str.
 String (const std::string &std_str, size_type str_idx, size_type str_num=npos)
 Constructs a new string initialised with characters from the given std::string object.
 String (const utf8 *utf8_str)
 Constructs a new String object and initialise it using the provided utf8 encoded string buffer.
 String (const utf8 *utf8_str, size_type chars_len)
 Constructs a new String object and initialise it using the provided utf8 encoded string buffer.
 String (size_type num, utf32 code_point)
 Constructs a new String that is initialised with the specified code point.
 String (const_iterator iter_beg, const_iterator iter_end)
 Construct a new string object and initialise it with code-points from the range [beg, end).
 String (const char *cstr)
 Constructs a new String object and initialise it using the provided c-string.
 String (const char *chars, size_type chars_len)
 Constructs a new String object and initialise it using characters from the provided char array.
size_type size (void) const
 Returns the size of the String in code points.
size_type length (void) const
 Returns the size of the String in code points.
bool empty (void) const
 Returns true if the String is empty.
size_type capacity (void) const
 Return the number of code points that the String could hold before a re-allocation would be required.
void reserve (size_type num=0)
 Specifies the amount of reserve capacity to allocate.
int compare (const String &str) const
 Compares this String with the String 'str'.
int compare (size_type idx, size_type len, const String &str, size_type str_idx=0, size_type str_len=npos) const
 Compares code points from this String with code points from the String 'str'.
int compare (const std::string &std_str) const
 Compares this String with the std::string 'std_str'.
int compare (size_type idx, size_type len, const std::string &std_str, size_type str_idx=0, size_type str_len=npos) const
 Compares code points from this String with code points from the std::string 'std_str'.
int compare (const utf8 *utf8_str) const
 Compares this String with the null-terminated utf8 encoded 'utf8_str'.
int compare (size_type idx, size_type len, const utf8 *utf8_str) const
 Compares code points from this String with the null-terminated utf8 encoded 'utf8_str'.
int compare (size_type idx, size_type len, const utf8 *utf8_str, size_type str_cplen) const
 Compares code points from this String with the utf8 encoded data in buffer 'utf8_str'.
int compare (const char *cstr) const
 Compares this String with the given c-string.
int compare (size_type idx, size_type len, const char *cstr) const
 Compares code points from this String with the given c-string.
int compare (size_type idx, size_type len, const char *chars, size_type chars_len) const
 Compares code points from this String with chars in the given char array.
reference operator[] (size_type idx)
 Returns the code point at the given index.
value_type operator[] (size_type idx) const
 Returns the code point at the given index.
reference at (size_type idx)
 Returns the code point at the given index.
const_reference at (size_type idx) const
 Returns the code point at the given index.
const char * c_str (void) const
 Returns contents of the String as a null terminated string of utf8 encoded data.
const utf8 * data (void) const
 Returns contents of the String as utf8 encoded data.
utf32 * ptr (void)
 Returns a pointer to the buffer in use.
const utf32 * ptr (void) const
 Returns a pointer to the buffer in use. (const version).
size_type copy (utf8 *buf, size_type len=npos, size_type idx=0) const
 Copies an area of the String into the provided buffer as encoded utf8 data.
size_type utf8_stream_len (size_type num=npos, size_type idx=0) const
 Return the number of utf8 code units required to hold an area of the String when encoded as utf8 data.
Stringoperator= (const String &str)
 Assign the value of String str to this String.
Stringassign (const String &str, size_type str_idx=0, size_type str_num=npos)
 Assign a sub-string of String str to this String.
Stringoperator= (const std::string &std_str)
 Assign the value of std::string std_str to this String.
Stringassign (const std::string &std_str, size_type str_idx=0, size_type str_num=npos)
 Assign a sub-string of std::string std_str to this String.
Stringoperator= (const utf8 *utf8_str)
 Assign to this String the string value represented by the given null-terminated utf8 encoded data.
Stringassign (const utf8 *utf8_str)
 Assign to this String the string value represented by the given null-terminated utf8 encoded data.
Stringassign (const utf8 *utf8_str, size_type str_num)
 Assign to this String the string value represented by the given utf8 encoded data.
Stringoperator= (utf32 code_point)
 Assigns the specified utf32 code point to this String. Result is always a String 1 code point in length.
Stringassign (size_type num, utf32 code_point)
 Assigns the specified code point repeatedly to the String.
Stringoperator= (const char *cstr)
 Assign to this String the given C-string.
Stringassign (const char *cstr)
 Assign to this String the given C-string.
Stringassign (const char *chars, size_type chars_len)
 Assign to this String a number of chars from a char array.
void swap (String &str)
 Swaps the value of this String with the given String str.
Stringoperator+= (const String &str)
 Appends the String str.
Stringappend (const String &str, size_type str_idx=0, size_type str_num=npos)
 Appends a sub-string of the String str.
Stringoperator+= (const std::string &std_str)
 Appends the std::string std_str.
Stringappend (const std::string &std_str, size_type str_idx=0, size_type str_num=npos)
 Appends a sub-string of the std::string std_str.
Stringoperator+= (const utf8 *utf8_str)
 Appends to the String the null-terminated utf8 encoded data in the buffer utf8_str.
Stringappend (const utf8 *utf8_str)
 Appends to the String the null-terminated utf8 encoded data in the buffer utf8_str.
Stringappend (const utf8 *utf8_str, size_type len)
 Appends to the String the utf8 encoded data in the buffer utf8_str.
Stringoperator+= (utf32 code_point)
 Appends a single code point to the string.
Stringappend (size_type num, utf32 code_point)
 Appends a single code point multiple times to the string.
void push_back (utf32 code_point)
 Appends a single code point to the string.
Stringappend (const_iterator iter_beg, const_iterator iter_end)
 Appends the code points in the reange [beg, end).
Stringoperator+= (const char *cstr)
 Appends to the String the given c-string.
Stringappend (const char *cstr)
 Appends to the String the given c-string.
Stringappend (const char *chars, size_type chars_len)
 Appends to the String chars from the given char array.
Stringinsert (size_type idx, const String &str)
 Inserts the given String object at the specified position.
Stringinsert (size_type idx, const String &str, size_type str_idx, size_type str_num)
 Inserts a sub-string of the given String object at the specified position.
Stringinsert (size_type idx, const std::string &std_str)
 Inserts the given std::string object at the specified position.
Stringinsert (size_type idx, const std::string &std_str, size_type str_idx, size_type str_num)
 Inserts a sub-string of the given std::string object at the specified position.
Stringinsert (size_type idx, const utf8 *utf8_str)
 Inserts the given null-terminated utf8 encoded data at the specified position.
Stringinsert (size_type idx, const utf8 *utf8_str, size_type len)
 Inserts the given utf8 encoded data at the specified position.
Stringinsert (size_type idx, size_type num, utf32 code_point)
 Inserts a code point multiple times into the String.
void insert (iterator pos, size_type num, utf32 code_point)
 Inserts a code point multiple times into the String.
iterator insert (iterator pos, utf32 code_point)
 Inserts a single code point into the String.
void insert (iterator iter_pos, const_iterator iter_beg, const_iterator iter_end)
 Inserts code points specified by the range [beg, end).
Stringinsert (size_type idx, const char *cstr)
 Inserts the given c-string at the specified position.
Stringinsert (size_type idx, const char *chars, size_type chars_len)
 Inserts chars from the given char array at the specified position.
void clear (void)
 Removes all data from the String.
Stringerase (void)
 Removes all data from the String.
Stringerase (size_type idx)
 Erase a single code point from the string.
Stringerase (size_type idx, size_type len=npos)
 Erase a range of code points.
Stringerase (iterator pos)
 Erase the code point described by the given iterator.
Stringerase (iterator iter_beg, iterator iter_end)
 Erase a range of code points described by the iterators [beg, end).
void resize (size_type num)
 Resizes the String either by inserting default utf32 code points to make it larger, or by truncating to make it smaller.
void resize (size_type num, utf32 code_point)
 Resizes the String either by inserting the given utf32 code point to make it larger, or by truncating to make it smaller.
Stringreplace (size_type idx, size_type len, const String &str)
 Replace code points in the String with the specified String object.
Stringreplace (iterator iter_beg, iterator iter_end, const String &str)
 Replace the code points in the range [beg, end) with the specified String object.
Stringreplace (size_type idx, size_type len, const String &str, size_type str_idx, size_type str_num)
 Replace code points in the String with a specified sub-string of a given String object.
Stringreplace (size_type idx, size_type len, const std::string &std_str)
 Replace code points in the String with the specified std::string object.
Stringreplace (iterator iter_beg, iterator iter_end, const std::string &std_str)
 Replace the code points in the range [beg, end) with the specified std::string object.
Stringreplace (size_type idx, size_type len, const std::string &std_str, size_type str_idx, size_type str_num)
 Replace code points in the String with a specified sub-string of a given std::string object.
Stringreplace (size_type idx, size_type len, const utf8 *utf8_str)
 Replace code points in the String with the specified null-terminated utf8 encoded data.
Stringreplace (iterator iter_beg, iterator iter_end, const utf8 *utf8_str)
 Replace the code points in the range [beg, end) with the specified null-terminated utf8 encoded data.
Stringreplace (size_type idx, size_type len, const utf8 *utf8_str, size_type str_len)
 Replace code points in the String with the specified utf8 encoded data.
Stringreplace (iterator iter_beg, iterator iter_end, const utf8 *utf8_str, size_type str_len)
 Replace the code points in the range [beg, end) with the specified null-terminated utf8 encoded data.
Stringreplace (size_type idx, size_type len, size_type num, utf32 code_point)
 Replaces a specified range of code points with occurrences of a given code point.
Stringreplace (iterator iter_beg, iterator iter_end, size_type num, utf32 code_point)
 Replace the code points in the range [beg, end) with occurrences of a given code point.
Stringreplace (iterator iter_beg, iterator iter_end, const_iterator iter_newBeg, const_iterator iter_newEnd)
 Replace the code points in the range [beg, end) with code points from the range [newBeg, newEnd).
Stringreplace (size_type idx, size_type len, const char *cstr)
 Replace code points in the String with the specified c-string.
Stringreplace (iterator iter_beg, iterator iter_end, const char *cstr)
 Replace the code points in the range [beg, end) with the specified c-string.
Stringreplace (size_type idx, size_type len, const char *chars, size_type chars_len)
 Replace code points in the String with chars from the given char array.
Stringreplace (iterator iter_beg, iterator iter_end, const char *chars, size_type chars_len)
 Replace the code points in the range [beg, end) with chars from the given char array.
size_type find (utf32 code_point, size_type idx=0) const
 Search forwards for a given code point.
size_type rfind (utf32 code_point, size_type idx=npos) const
 Search backwards for a given code point.
size_type find (const String &str, size_type idx=0) const
 Search forwards for a sub-string.
size_type rfind (const String &str, size_type idx=npos) const
 Search backwards for a sub-string.
size_type find (const std::string &std_str, size_type idx=0) const
 Search forwards for a sub-string.
size_type rfind (const std::string &std_str, size_type idx=npos) const
 Search backwards for a sub-string.
size_type find (const utf8 *utf8_str, size_type idx=0) const
 Search forwards for a sub-string.
size_type rfind (const utf8 *utf8_str, size_type idx=npos) const
 Search backwards for a sub-string.
size_type find (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Search forwards for a sub-string.
size_type rfind (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Search backwards for a sub-string.
size_type find (const char *cstr, size_type idx=0) const
 Search forwards for a sub-string.
size_type rfind (const char *cstr, size_type idx=npos) const
 Search backwards for a sub-string.
size_type find (const char *chars, size_type idx, size_type chars_len) const
 Search forwards for a sub-string.
size_type rfind (const char *chars, size_type idx, size_type chars_len) const
 Search backwards for a sub-string.
size_type find_first_of (const String &str, size_type idx=0) const
 Find the first occurrence of one of a set of code points.
size_type find_first_not_of (const String &str, size_type idx=0) const
 Find the first code point that is not one of a set of code points.
size_type find_first_of (const std::string &std_str, size_type idx=0) const
 Find the first occurrence of one of a set of code points.
size_type find_first_not_of (const std::string &std_str, size_type idx=0) const
 Find the first code point that is not one of a set of code points.
size_type find_first_of (const utf8 *utf8_str, size_type idx=0) const
 Find the first occurrence of one of a set of code points.
size_type find_first_not_of (const utf8 *utf8_str, size_type idx=0) const
 Find the first code point that is not one of a set of code points.
size_type find_first_of (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Find the first occurrence of one of a set of code points.
size_type find_first_not_of (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Find the first code point that is not one of a set of code points.
size_type find_first_of (utf32 code_point, size_type idx=0) const
 Search forwards for a given code point.
size_type find_first_not_of (utf32 code_point, size_type idx=0) const
 Search forwards for the first code point that does not match a given code point.
size_type find_first_of (const char *cstr, size_type idx=0) const
 Find the first occurrence of one of a set of chars.
size_type find_first_not_of (const char *cstr, size_type idx=0) const
 Find the first code point that is not one of a set of chars.
size_type find_first_of (const char *chars, size_type idx, size_type chars_len) const
 Find the first occurrence of one of a set of chars.
size_type find_first_not_of (const char *chars, size_type idx, size_type chars_len) const
 Find the first code point that is not one of a set of chars.
size_type find_last_of (const String &str, size_type idx=npos) const
 Find the last occurrence of one of a set of code points.
size_type find_last_not_of (const String &str, size_type idx=npos) const
 Find the last code point that is not one of a set of code points.
size_type find_last_of (const std::string &std_str, size_type idx=npos) const
 Find the last occurrence of one of a set of code points.
size_type find_last_not_of (const std::string &std_str, size_type idx=npos) const
 Find the last code point that is not one of a set of code points.
size_type find_last_of (const utf8 *utf8_str, size_type idx=npos) const
 Find the last occurrence of one of a set of code points.
size_type find_last_not_of (const utf8 *utf8_str, size_type idx=npos) const
 Find the last code point that is not one of a set of code points.
size_type find_last_of (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Find the last occurrence of one of a set of code points.
size_type find_last_not_of (const utf8 *utf8_str, size_type idx, size_type str_len) const
 Find the last code point that is not one of a set of code points.
size_type find_last_of (utf32 code_point, size_type idx=npos) const
 Search for last occurrence of a given code point.
size_type find_last_not_of (utf32 code_point, size_type idx=npos) const
 Search for the last code point that does not match a given code point.
size_type find_last_of (const char *cstr, size_type idx=npos) const
 Find the last occurrence of one of a set of chars.
size_type find_last_not_of (const char *cstr, size_type idx=npos) const
 Find the last code point that is not one of a set of chars.
size_type find_last_of (const char *chars, size_type idx, size_type chars_len) const
 Find the last occurrence of one of a set of chars.
size_type find_last_not_of (const char *chars, size_type idx, size_type chars_len) const
 Find the last code point that is not one of a set of chars.
String substr (size_type idx=0, size_type len=npos) const
 Returns a substring of this String.
iterator begin (void)
 Return a forwards iterator that describes the beginning of the String.
const_iterator begin (void) const
 Return a constant forwards iterator that describes the beginning of the String.
iterator end (void)
 Return a forwards iterator that describes the end of the String.
const_iterator end (void) const
 Return a constant forwards iterator that describes the end of the String.
reverse_iterator rbegin (void)
 Return a reverse iterator that describes the beginning of the String.
const_reverse_iterator rbegin (void) const
 Return a constant reverse iterator that describes the beginning of the String.
reverse_iterator rend (void)
 Return a reverse iterator that describes the end of the String.
const_reverse_iterator rend (void) const
 Return a constant reverse iterator that describes the end of the String.

Static Public Member Functions

static size_type max_size (void)
 Returns the maximum size of a String.

Static Public Attributes

static const size_type npos = (String::size_type)(-1)
 Value used to represent 'not found' conditions and 'all code points' etc.

Classes

class  const_iterator
 Constant forward iterator class for String objects. More...
struct  FastLessCompare
 Functor that can be used as comparator in a std::map with String keys. It's faster than using the default, but the map will no longer be sorted alphabetically. More...
class  iterator
 Forward iterator class for String objects. More...


Detailed Description

String class used within the GUI system.

For the most part, this class can replace std::string in basic usage. However, currently String does not use the current locale, and also comparisons do not take into account the Unicode data tables, so are not 'correct' as such.


Constructor & Destructor Documentation

CEGUI::String::String ( const String str  )  [inline]

Copy constructor - Creates a new string with the same value as str.

Parameters:
str String object used to initialise the newly created string
Returns:
Nothing

CEGUI::String::String ( const String str,
size_type  str_idx,
size_type  str_num = npos 
) [inline]

Constructs a new string initialised with code points from another String object.

Parameters:
str String object used to initialise the newly created string
str_idx Starting code-point of str to be used when initialising the new String
str_num Maximum number of code points from str that are to be assigned to the new String
Returns:
Nothing

CEGUI::String::String ( const std::string &  std_str  )  [inline]

Constructs a new string and initialises it using the std::string std_str.

Parameters:
std_str The std::string object that is to be used to initialise the new String object.
Note:
The characters of std_str are taken to be unencoded data which represent Unicode code points 0x00..0xFF. No translation of the provided data will occur.
Returns:
Nothing
Exceptions:
std::length_error Thrown if resulting String object would be too big.

CEGUI::String::String ( const std::string &  std_str,
size_type  str_idx,
size_type  str_num = npos 
) [inline]

Constructs a new string initialised with characters from the given std::string object.

Parameters:
std_str std::string object used to initialise the newly created string
str_idx Starting character of std_str to be used when initialising the new String
Note:
The characters of std_str are taken to be unencoded data which represent Unicode code points 0x00..0xFF. No translation of the provided data will occur.
Parameters:
str_num Maximum number of characters from std_str that are to be assigned to the new String
Returns:
Nothing
Exceptions:
std::length_error Thrown if resulting String object would be too big.

CEGUI::String::String ( const utf8 *  utf8_str  )  [inline]

Constructs a new String object and initialise it using the provided utf8 encoded string buffer.

Parameters:
utf8_str Pointer to a buffer containing a null-terminated Unicode string encoded as utf8 data.
Note:
A basic string literal (cast to utf8*) can be passed to this function, provided that the string is comprised only of code points 0x00..0x7f. The use of extended ASCII characters (with values >0x7f) would result in incorrect behaviour as the String will attempt to 'decode' the data, with unpredictable results.
Returns:
Nothing
Exceptions:
std::length_error Thrown if resulting String object would be too big.

CEGUI::String::String ( const utf8 *  utf8_str,
size_type  chars_len 
) [inline]

Constructs a new String object and initialise it using the provided utf8 encoded string buffer.

A basic string literal (cast to utf8*) can be passed to this function, provided that the string is comprised only of code points 0x00..0x7f. The use of extended ASCII characters (with values >0x7f) would result in incorrect behaviour as the String will attempt to 'decode' the data, with unpredictable results.

Parameters:
utf8_str Pointer to a buffer containing Unicode string data encoded as utf8.
Note:
A basic string literal (cast to utf8*) can be passed to this function, provided that the string is comprised only of code points 0x00..0x7f. The use of extended ASCII characters (with values >0x7f) would result in incorrect behaviour as the String will attempt to 'decode' the data, with unpredictable results.