Logo Search packages:      
Sourcecode: ardour version File versions  Download package

Glib::ustring Class Reference

#include <ustring.h>

List of all members.


Detailed Description

Glib::ustring has much the same interface as std::string, but contains Unicode characters encoded as UTF-8.

About UTF-8 and ASCII
The standard character set ANSI_X3.4-1968 -- more commonly known as ASCII -- is a subset of UTF-8. So, if you want to, you can use Glib::ustring without even thinking about UTF-8.
Whenever ASCII is mentioned in this manual, we mean the real ASCII (i.e. as defined in ANSI_X3.4-1968), which contains only 7-bit characters. Glib::ustring can not be used with ASCII-compatible extended 8-bit charsets like ISO-8859-1. It's a good idea to avoid string literals containing non-ASCII characters (e.g. German umlauts) in source code, or at least you should use UTF-8 literals.
You can find a detailed UTF-8 and Unicode FAQ here: http://www.cl.cam.ac.uk/~mgk25/unicode.html
Glib::ustring vs. std::string
Glib::ustring has implicit type conversions to and from std::string. These conversions do not convert to/from the current locale (see Glib::locale_from_utf8() and Glib::locale_to_utf8() if you need that). You can always use std::string instead of Glib::ustring -- however, using std::string with multi-byte characters is quite hard. For instance, std::string::operator[] might return a byte in the middle of a character, and std::string::length() returns the number of bytes rather than characters. So don't do that without a good reason.
In a perfect world the C++ Standard Library would contain a UTF-8 string class. Unfortunately, the C++ standard doesn't mention UTF-8 at all. Note that std::wstring is not a UTF-8 string class because it contains only fixed-width characters (where width could be 32, 16, or even 8 bits).
Glib::ustring and stream input/output
The stream I/O operators, that is operator<<() and operator>>(), perform implicit charset conversion to/from the current locale. If that's not what you intented (e.g. when writing to a configuration file that should always be UTF-8 encoded) use ustring::raw() to override this behaviour.
If you're using std::ostringstream to build strings for display in the user interface, you must convert the result back to UTF-8 as shown below:
 std::ostringstream output;
 output.imbue(std::locale("")); // use the user's locale for this stream
 output << percentage << " % done";
 label->set_text(Glib::locale_to_utf8(output.str()));
Implementation notes
Glib::ustring does not inherit from std::string, because std::string was intended to be a final class. For instance, it does not have a virtual destructor. Also, a HAS-A relationship is more appropriate because ustring can't just enhance the std::string interface. Rather, it has to reimplement the interface so that all operations are based on characters instead of bytes.

Definition at line 200 of file ustring.h.


Public Types

typedef ustring_Iterator
< std::string::const_iterator > 
const_iterator
typedef const gunichar & const_reference
typedef std::reverse_iterator
< const_iterator
const_reverse_iterator
typedef
std::string::difference_type 
difference_type
typedef ustring_Iterator
< std::string::iterator > 
iterator
typedef gunichar & reference
typedef std::reverse_iterator
< iterator
reverse_iterator
typedef std::string::size_type size_type
typedef gunichar value_type

Public Member Functions

ustringoperator= (const ustring &other)
void swap (ustring &other)
template<class In>
 ustring (In pbegin, In pend)
 ustring (size_type n, char c)
 ustring (size_type n, gunichar uc)
 ustring (const char *src)
 ustring (const char *src, size_type n)
 ustring (const ustring &src, size_type i, size_type n=npos)
 ustring (const std::string &src)
 ustring (const ustring &other)
 ustring ()
Append to the string.
template<class In>
ustringappend (In pbegin, In pend)
ustringappend (size_type n, char c)
ustringappend (size_type n, gunichar uc)
ustringappend (const char *src)
ustringappend (const char *src, size_type n)
ustringappend (const ustring &src, size_type i, size_type n)
ustringappend (const ustring &src)
ustringoperator+= (char c)
ustringoperator+= (gunichar uc)
ustringoperator+= (const char *src)
ustringoperator+= (const ustring &src)
void push_back (char c)
void push_back (gunichar uc)
Assign new contents.
template<class In>
ustringassign (In pbegin, In pend)
ustringassign (size_type n, char c)
ustringassign (size_type n, gunichar uc)
ustringassign (const char *src)
ustringassign (const char *src, size_type n)
ustringassign (const ustring &src, size_type i, size_type n)
ustringassign (const ustring &src)
ustringoperator= (char c)
ustringoperator= (gunichar uc)
ustringoperator= (const char *src)
ustringoperator= (const std::string &src)
Extract characters and sub-strings.
value_type at (size_type i) const
value_type operator[] (size_type i) const
ustring substr (size_type i=0, size_type n=npos) const
Access a sequence of characters.
const_iterator begin () const
iterator begin ()
const_iterator end () const
iterator end ()
const_reverse_iterator rbegin () const
reverse_iterator rbegin ()
const_reverse_iterator rend () const
reverse_iterator rend ()
Retrieve the string's size.
size_type bytes () const
bool empty () const
size_type length () const
size_type size () const
Get a per-byte representation of the string.
const char * c_str () const
size_type copy (char *dest, size_type n, size_type i=0) const
const char * data () const
 operator std::string () const
const std::string & raw () const
Control the allocated memory.
size_type capacity () const
size_type max_size () const
void reserve (size_type n=0)
Character case conversion.
ustring casefold () const
ustring lowercase () const
ustring uppercase () const
Compare and collate.
std::string casefold_collate_key () const
std::string collate_key () const
int compare (size_type i, size_type n, const char *rhs) const
int compare (size_type i, size_type n, const char *rhs, size_type n2) const
int compare (size_type i, size_type n, const ustring &rhs, size_type i2, size_type n2) const
int compare (size_type i, size_type n, const ustring &rhs) const
int compare (const char *rhs) const
int compare (const ustring &rhs) const
Erase sub-strings.
void clear ()
iterator erase (iterator pbegin, iterator pend)
iterator erase (iterator p)
ustringerase ()
ustringerase (size_type i, size_type n=npos)
Find sub-strings.
size_type find (char c, size_type i=0) const
size_type find (gunichar uc, size_type i=0) const
size_type find (const char *str, size_type i=0) const
size_type find (const char *str, size_type i, size_type n) const
size_type find (const ustring &str, size_type i=0) const
size_type rfind (char c, size_type i=npos) const
size_type rfind (gunichar uc, size_type i=npos) const
size_type rfind (const char *str, size_type i=npos) const
size_type rfind (const char *str, size_type i, size_type n) const
size_type rfind (const ustring &str, size_type i=npos) const
Match against a set of characters.
size_type find_first_not_of (char c, size_type i=0) const
size_type find_first_not_of (gunichar uc, size_type i=0) const
size_type find_first_not_of (const char *match, size_type i=0) const
size_type find_first_not_of (const char *match, size_type i, size_type n) const
size_type find_first_not_of (const ustring &match, size_type i=0) const
size_type find_first_of (char c, size_type i=0) const
size_type find_first_of (gunichar uc, size_type i=0) const
size_type find_first_of (const char *match, size_type i=0) const
size_type find_first_of (const char *match, size_type i, size_type n) const
size_type find_first_of (const ustring &match, size_type i=0) const
size_type find_last_not_of (char c, size_type i=npos) const
size_type find_last_not_of (gunichar uc, size_type i=npos) const
size_type find_last_not_of (const char *match, size_type i=npos) const
size_type find_last_not_of (const char *match, size_type i, size_type n) const
size_type find_last_not_of (const ustring &match, size_type i=npos) const
size_type find_last_of (char c, size_type i=npos) const
size_type find_last_of (gunichar uc, size_type i=npos) const
size_type find_last_of (const char *match, size_type i=npos) const
size_type find_last_of (const char *match, size_type i, size_type n) const
size_type find_last_of (const ustring &match, size_type i=npos) const
Insert into the string.
template<class In>
void insert (iterator p, In pbegin, In pend)
void insert (iterator p, size_type n, char c)
void insert (iterator p, size_type n, gunichar uc)
iterator insert (iterator p, char c)
iterator insert (iterator p, gunichar uc)
ustringinsert (size_type i, size_type n, char c)
ustringinsert (size_type i, size_type n, gunichar uc)
ustringinsert (size_type i, const char *src)
ustringinsert (size_type i, const char *src, size_type n)
ustringinsert (size_type i, const ustring &src, size_type i2, size_type n)
ustringinsert (size_type i, const ustring &src)
UTF-8 utilities.
bool is_ascii () const
ustring normalize (NormalizeMode mode=NORMALIZE_DEFAULT_COMPOSE) const
bool validate (const_iterator &first_invalid) const
bool validate (iterator &first_invalid)
bool validate () const
Replace sub-strings.
template<class In>
ustringreplace (iterator pbegin, iterator pend, In pbegin2, In pend2)
ustringreplace (iterator pbegin, iterator pend, size_type n, char c)
ustringreplace (iterator pbegin, iterator pend, size_type n, gunichar uc)
ustringreplace (iterator pbegin, iterator pend, const char *src)
ustringreplace (iterator pbegin, iterator pend, const char *src, size_type n)
ustringreplace (iterator pbegin, iterator pend, const ustring &src)
ustringreplace (size_type i, size_type n, size_type n2, char c)
ustringreplace (size_type i, size_type n, size_type n2, gunichar uc)
ustringreplace (size_type i, size_type n, const char *src)
ustringreplace (size_type i, size_type n, const char *src, size_type n2)
ustringreplace (size_type i, size_type n, const ustring &src, size_type i2, size_type n2)
ustringreplace (size_type i, size_type n, const ustring &src)
Change the string's size.
void resize (size_type n, char c='\0')
void resize (size_type n, gunichar uc)

Static Public Attributes

static const size_type npos = std::string::npos

Private Attributes

std::string string_

Related Functions

(Note that these are not member functions.)

bool operator!= (const char *lhs, const ustring &rhs)
bool operator!= (const ustring &lhs, const char *rhs)
bool operator!= (const ustring &lhs, const ustring &rhs)
ustring operator+ (char lhs, const ustring &rhs)
ustring operator+ (const ustring &lhs, char rhs)
ustring operator+ (gunichar lhs, const ustring &rhs)
ustring operator+ (const ustring &lhs, gunichar rhs)
ustring operator+ (const char *lhs, const ustring &rhs)
ustring operator+ (const ustring &lhs, const char *rhs)
ustring operator+ (const ustring &lhs, const ustring &rhs)
bool operator< (const char *lhs, const ustring &rhs)
bool operator< (const ustring &lhs, const char *rhs)
bool operator< (const ustring &lhs, const ustring &rhs)
std::ostream & operator<< (std::ostream &os, const Glib::ustring &utf8_string)
bool operator<= (const char *lhs, const ustring &rhs)
bool operator<= (const ustring &lhs, const char *rhs)
bool operator<= (const ustring &lhs, const ustring &rhs)
bool operator== (const char *lhs, const ustring &rhs)
bool operator== (const ustring &lhs, const char *rhs)
bool operator== (const ustring &lhs, const ustring &rhs)
bool operator> (const char *lhs, const ustring &rhs)
bool operator> (const ustring &lhs, const char *rhs)
bool operator> (const ustring &lhs, const ustring &rhs)
bool operator>= (const char *lhs, const ustring &rhs)
bool operator>= (const ustring &lhs, const char *rhs)
bool operator>= (const ustring &lhs, const ustring &rhs)
std::istream & operator>> (std::istream &is, Glib::ustring &utf8_string)
void swap (ustring &lhs, ustring &rhs)

Classes

struct  SequenceToString
struct  SequenceToString< Glib::ustring::const_iterator, gunichar >
struct  SequenceToString< Glib::ustring::iterator, gunichar >
struct  SequenceToString< In, char >
struct  SequenceToString< In, gunichar >

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

Generated by  Doxygen 1.6.0   Back to index