String Class Reference

#include <Pt/String.h>

Unicode capable basic_string. More...

Public Member Functions

 String (const allocator_type &a=allocator_type())
 Default Constructor.
 
 String (const Pt::Char *str, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const Pt::Char *str, size_type n, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const wchar_t *str, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const wchar_t *str, size_type n, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const char *str, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const char *str, size_type n, const allocator_type &a=allocator_type())
 Constructor.
 
 String (size_type n, Pt::Char c, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const String &str)
 Copy Constructor.
 
 String (const String &str, const allocator_type &a)
 Constructor.
 
 String (const String &str, size_type pos, size_type n=npos, const allocator_type &a=allocator_type())
 Constructor.
 
 String (const Pt::Char *begin, const Pt::Char *end, const allocator_type &a=allocator_type())
 Constructor.
 
 ~String ()
 Destructor.
 
Stringappend (const Pt::Char *str)
 Append content to the string.
 
Stringappend (const Pt::Char *str, size_type n)
 Append content to the string.
 
Stringappend (size_type n, Pt::Char ch)
 Append content to the string.
 
Stringappend (const String &str)
 Append content to the string.
 
Stringappend (const String &str, size_type pos, size_type n)
 Append content to the string.
 
Stringappend (const Pt::Char *begin, const Pt::Char *end)
 Append content to the string.
 
Stringassign (const String &str)
 Assign content to the string.
 
Stringassign (const String &str, size_type pos, size_type n)
 Assign content to the string.
 
Stringassign (const wchar_t *str)
 Assign content to the string.
 
Stringassign (const wchar_t *str, size_type n)
 Assign content to the string.
 
Stringassign (const Pt::Char *str)
 Assign content to the string.
 
Stringassign (const Pt::Char *str, size_type length)
 Assign content to the string.
 
Stringassign (const char *str)
 Assign content to the string.
 
Stringassign (const char *str, size_type length)
 Assign content to the string.
 
Stringassign (size_type n, Pt::Char c)
 Assign content to the string.
 
reference at (size_type n)
 Random access to characters.
 
const_reference at (size_type n) const
 Random access to characters.
 
iterator begin ()
 Returns an iterator to the begin of the string.
 
const_iterator begin () const
 Returns an iterator to the begin of the string.
 
const Pt::Charc_str () const
 Returns a null terminated C string.
 
size_type capacity () const
 Returns the capacity.
 
void clear ()
 Clears the string.
 
int compare (const String &str) const
 Compare strings.
 
int compare (const Pt::Char *str) const
 Compare strings.
 
int compare (const Pt::Char *str, size_type n) const
 Compare strings.
 
int compare (const wchar_t *str) const
 Compare strings.
 
int compare (const wchar_t *str, size_type n) const
 Compare strings.
 
int compare (const char *str) const
 Compare strings.
 
int compare (const char *str, size_type n) const
 Compare strings.
 
int compare (size_type pos, size_type n, const String &str) const
 Compare strings.
 
int compare (size_type pos, size_type n, const String &str, size_type pos2, size_type n2) const
 Compare strings.
 
int compare (size_type pos, size_type n, const Pt::Char *str) const
 Compare strings.
 
int compare (size_type pos, size_type n, const Pt::Char *str, size_type n2) const
 Compare strings.
 
size_type copy (Pt::Char *a, size_type n, size_type pos=0) const
 Copy characters to a buffer.
 
const Pt::Chardata () const
 Returns the string character buffer.
 
bool empty () const
 Returns true if empty.
 
iterator end ()
 Returns an iterator to the end of the string.
 
const_iterator end () const
 Returns an iterator to the end of the string.
 
Stringerase (size_type pos=0, size_type n=npos)
 Erase characters from the string.
 
iterator erase (iterator pos)
 Erase characters from the string.
 
iterator erase (iterator first, iterator last)
 Erase characters from the string.
 
size_type find (const String &str, size_type pos=0) const
 Find content in the string.
 
size_type find (const Pt::Char *str, size_type pos, size_type n) const
 Find content in the string.
 
size_type find (const Pt::Char *str, size_type pos=0) const
 Find content in the string.
 
size_type find (Pt::Char ch, size_type pos=0) const
 Find content in the string.
 
size_type find_first_not_of (const String &str, size_type pos=0) const
 Find content in the string.
 
size_type find_first_not_of (const Pt::Char *s, size_type pos, size_type n) const
 Find content in the string.
 
size_type find_first_not_of (const Pt::Char *str, size_type pos=0) const
 Find content in the string.
 
size_type find_first_not_of (const Pt::Char ch, size_type pos=0) const
 Find content in the string.
 
size_type find_first_of (const String &str, size_type pos=0) const
 Find content in the string.
 
size_type find_first_of (const Pt::Char *s, size_type pos, size_type n) const
 Find content in the string.
 
size_type find_first_of (const Pt::Char *str, size_type pos=0) const
 Find content in the string.
 
size_type find_first_of (const Pt::Char ch, size_type pos=0) const
 Find content in the string.
 
size_type find_last_not_of (const String &str, size_type pos=npos) const
 Find content in the string.
 
size_type find_last_not_of (const Pt::Char *tok, size_type pos, size_type n) const
 Find content in the string.
 
size_type find_last_not_of (const Pt::Char *str, size_type pos=npos) const
 Find content in the string.
 
size_type find_last_not_of (Pt::Char ch, size_type pos=npos) const
 Find content in the string.
 
size_type find_last_of (const String &str, size_type pos=npos) const
 Find content in the string.
 
size_type find_last_of (const Pt::Char *s, size_type pos, size_type n) const
 Find content in the string.
 
size_type find_last_of (const Pt::Char *str, size_type pos=npos) const
 Find content in the string.
 
size_type find_last_of (const Pt::Char ch, size_type pos=npos) const
 Find content in the string.
 
allocator_type get_allocator () const
 Returns the used allocator.
 
Stringinsert (size_type pos, const Pt::Char *str)
 Insert into string.
 
Stringinsert (size_type pos, const Pt::Char *str, size_type n)
 Insert into string.
 
Stringinsert (size_type pos, size_type n, Pt::Char ch)
 Insert into string.
 
Stringinsert (size_type pos, const String &str)
 Insert into string.
 
Stringinsert (size_type pos, const String &str, size_type pos2, size_type n)
 Insert into string.
 
Stringinsert (iterator p, Pt::Char ch)
 Insert into string.
 
Stringinsert (iterator p, size_type n, Pt::Char ch)
 Insert into string.
 
size_type length () const
 Returns the length of the string.
 
size_type max_size () const
 Returns the maximum possible length.
 
std::string narrow (char dfault= '?') const
 Narrow string to 8-bit.
 
Stringoperator+= (const String &str)
 Append a string.
 
Stringoperator+= (const Pt::Char *str)
 Append a string.
 
Stringoperator+= (Pt::Char c)
 Append a character.
 
Stringoperator= (const String &str)
 Assignment operator.
 
Stringoperator= (const wchar_t *str)
 Assignment operator.
 
Stringoperator= (const char *str)
 Assignment operator.
 
Stringoperator= (const Pt::Char *str)
 Assignment operator.
 
Stringoperator= (Pt::Char ch)
 Assignment operator.
 
reference operator[] (size_type n)
 Random access to characters.
 
const_reference operator[] (size_type n) const
 Random access to characters.
 
void push_back (Pt::Char ch)
 Append a character.
 
reverse_iterator rbegin ()
 Returns an reverse iterator to the end of the string.
 
const_reverse_iterator rbegin () const
 Returns an reverse iterator to the end of the string.
 
reverse_iterator rend ()
 Returns an reverse iterator to the begin of the string.
 
const_reverse_iterator rend () const
 Returns an reverse iterator to the begin of the string.
 
Stringreplace (size_type pos, size_type n, const Pt::Char *str)
 Replace portion of the string.
 
Stringreplace (size_type pos, size_type n, const Pt::Char *str, size_type n2)
 Replace portion of the string.
 
Stringreplace (size_type pos, size_type n, size_type n2, Pt::Char ch)
 Replace portion of the string.
 
Stringreplace (size_type pos, size_type n, const String &str)
 Replace portion of the string.
 
Stringreplace (size_type pos, size_type n, const String &str, size_type pos2, size_type n2)
 Replace portion of the string.
 
Stringreplace (iterator i1, iterator i2, const Pt::Char *str)
 Replace portion of the string.
 
Stringreplace (iterator i1, iterator i2, const Pt::Char *str, size_type n)
 Replace portion of the string.
 
Stringreplace (iterator i1, iterator i2, size_type n, Pt::Char ch)
 Replace portion of the string.
 
Stringreplace (iterator i1, iterator i2, const String &str)
 Replace portion of the string.
 
void reserve (std::size_t n=0)
 Reserves space.
 
void resize (std::size_t n, Pt::Char ch=value_type())
 Resizes the string.
 
size_type rfind (const String &str, size_type pos=npos) const
 Find content in the string.
 
size_type rfind (const Pt::Char *str, size_type pos, size_type n) const
 Find content in the string.
 
size_type rfind (const Pt::Char *str, size_type pos=npos) const
 Find content in the string.
 
size_type rfind (Pt::Char ch, size_type pos=npos) const
 Find content in the string.
 
size_type size () const
 Returns the length of the string.
 
String substr (size_type pos=0, size_type n=npos) const
 Returns a substring.
 
void swap (String &str)
 Swaps with another string.
 
template<typename OutIterT >
OutIterT toUtf16 (OutIterT to) const
 Convert to UTF-16.
 

Static Public Member Functions

template<typename InIterT >
static String fromUtf16 (InIterT from, InIterT fromEnd)
 Convert from UTF-16.
 
static String widen (const char *str)
 Widen 8-bit string .
 
static String widen (const std::string &str)
 Widen 8-bit string .
 

Related Functions

bool operator!= (const String &a, const String &b)
 Compares two strings.
 
bool operator!= (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator!= (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator!= (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator!= (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator!= (const String &a, const char *b)
 Compares two strings.
 
bool operator!= (const char *b, const String &a)
 Compares two strings.
 
String operator+ (const String &a, const String &b)
 Concatenates two strings.
 
String operator+ (const String &a, const Pt::Char *b)
 Concatenates two strings.
 
String operator+ (const Pt::Char *a, const String &b)
 Concatenates two strings.
 
String operator+ (const String &a, Pt::Char b)
 Concatenates two strings.
 
String operator+ (Pt::Char a, const String &b)
 Concatenates two strings.
 
bool operator< (const String &a, const String &b)
 Compares two strings.
 
bool operator< (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator< (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator< (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator< (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator< (const String &a, const char *b)
 Compares two strings.
 
bool operator< (const char *b, const String &a)
 Compares two strings.
 
ostream & operator<< (ostream &out, const String &str)
 Stream insertion operator.
 
bool operator<= (const String &a, const String &b)
 Compares two strings.
 
bool operator<= (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator<= (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator<= (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator<= (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator<= (const String &a, const char *b)
 Compares two strings.
 
bool operator<= (const char *b, const String &a)
 Compares two strings.
 
bool operator== (const String &a, const String &b)
 Compares two strings.
 
bool operator== (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator== (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator== (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator== (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator== (const String &a, const char *b)
 Compares two strings.
 
bool operator== (const char *b, const String &a)
 Compares two strings.
 
bool operator> (const String &a, const String &b)
 Compares two strings.
 
bool operator> (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator> (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator> (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator> (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator> (const String &a, const char *b)
 Compares two strings.
 
bool operator> (const char *b, const String &a)
 Compares two strings.
 
bool operator>= (const String &a, const String &b)
 Compares two strings.
 
bool operator>= (const Pt::Char *a, const String &b)
 Compares two strings.
 
bool operator>= (const String &a, const Pt::Char *b)
 Compares two strings.
 
bool operator>= (const String &a, const wchar_t *b)
 Compares two strings.
 
bool operator>= (const wchar_t *b, const String &a)
 Compares two strings.
 
bool operator>= (const String &a, const char *b)
 Compares two strings.
 
bool operator>= (const char *b, const String &a)
 Compares two strings.
 
void swap (String &a, String &b)
 Swaps two strings.
 

Detailed Description

This class Pt::String is not yet another unicode string class, but it is a specialization of the std::basic_string template for the unicode character type Pt::Char:

typedef std::basic_string<Pt::Char> String;

It offers all the functionality of the std::basic_string template. This has the advantage, that all generic algorithms that work with std::basic_string should also work with Pt::String. Please refer to a standard c++ manual for a complete overview. Additional methods make it easier to work with other character types. For example, the relational operators are also overloaded for char and wchar_t.