Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

otk::ustring Class Reference

#include <ustring.hh>

Collaboration diagram for otk::ustring:

Collaboration graph
[legend]
List of all members.

Detailed Description

This class provides a simple wrapper to a std::string that can be encoded as UTF-8. The ustring::utf() member specifies if the given string is UTF-8 encoded. ustrings default to specifying UTF-8 encoding.

This class does not handle extended 8-bit ASCII charsets like ISO-8859-1.

More info on Unicode and UTF-8 can be found here: http://www.cl.cam.ac.uk/~mgk25/unicode.html

This does not subclass std::string, because std::string was intended to be a final class. For instance, it does not have a virtual destructor.

Definition at line 103 of file ustring.hh.

Public Types

typedef std::string::size_type size_type
typedef std::string::difference_type difference_type
typedef unichar value_type

Public Methods

 ustring (bool utf8=true)
 ~ustring ()
 ustring (const ustring &other)
ustring & operator= (const ustring &other)
 ustring (const std::string &src, bool utf8=true)
 ustring (const char *src, bool utf8=true)
ustring & operator+= (const ustring &src)
ustring & operator+= (const char *src)
ustring & operator+= (char c)
ustring::size_type size () const
ustring::size_type bytes () const
ustring::size_type capacity () const
ustring::size_type max_size () const
bool empty () const
void clear ()
ustring & erase (size_type i, size_type n=npos)
void resize (size_type n, char c='\0')
value_type operator[] (size_type i) const
bool operator== (const ustring &other) const
bool operator== (const std::string &other) const
bool operator== (const char *other) const
const char * data () const
const char * c_str () const
bool utf8 () const
void setUtf8 (bool utf8)

Static Public Attributes

const size_type npos = std::string::npos

Private Attributes

std::string _string
bool _utf8


Member Typedef Documentation

typedef std::string::difference_type otk::ustring::difference_type
 

Definition at line 109 of file ustring.hh.

typedef std::string::size_type otk::ustring::size_type
 

Definition at line 108 of file ustring.hh.

Referenced by erase(), and resize().

typedef unichar otk::ustring::value_type
 

Definition at line 111 of file ustring.hh.


Constructor & Destructor Documentation

otk::ustring::ustring bool    utf8 = true
 

Definition at line 114 of file ustring.cc.

00115   : _utf8(utf8)
00116 {
00117 }

otk::ustring::~ustring  
 

Definition at line 119 of file ustring.cc.

00120 {
00121 }

otk::ustring::ustring const ustring &    other
 

Definition at line 123 of file ustring.cc.

00124   : _string(other._string), _utf8(other._utf8)
00125 {
00126 }

otk::ustring::ustring const std::string &    src,
bool    utf8 = true
 

Definition at line 135 of file ustring.cc.

00136   : _string(src), _utf8(utf8)
00137 {
00138 }

otk::ustring::ustring const char *    src,
bool    utf8 = true
 

Definition at line 140 of file ustring.cc.

00141   : _string(src), _utf8(utf8)
00142 {
00143 }


Member Function Documentation

ustring::size_type otk::ustring::bytes   const
 

Definition at line 173 of file ustring.cc.

References _string.

Referenced by otk::RenderControl::drawString(), otk::Font::measureString(), and otk::Property::set().

00174 {
00175   return _string.size();
00176 }

const char * otk::ustring::c_str   const
 

Definition at line 252 of file ustring.cc.

References _string.

Referenced by otk::RenderControl::drawString(), otk::Font::measureString(), and otk::Property::set().

00253 {
00254   return _string.c_str();
00255 }

ustring::size_type otk::ustring::capacity   const
 

Definition at line 178 of file ustring.cc.

References _string.

00179 {
00180   return _string.capacity();
00181 }

void otk::ustring::clear  
 

Definition at line 193 of file ustring.cc.

References _string.

00194 {
00195   _string.erase();
00196 }

const char * otk::ustring::data   const
 

Definition at line 247 of file ustring.cc.

References _string.

00248 {
00249   return _string.data();
00250 }

bool otk::ustring::empty   const
 

Definition at line 188 of file ustring.cc.

References _string.

Referenced by ob::Client::updateIconTitle(), and ob::Client::updateTitle().

00189 {
00190   return _string.empty();
00191 }

ustring & otk::ustring::erase size_type    i,
size_type    n = npos
 

Definition at line 198 of file ustring.cc.

References _string, npos, size_type, and otk::utf8_byte_offset().

Referenced by ob::Frame::adjustSize(), and resize().

00199 {
00200   if (_utf8) {
00201     // find a proper offset
00202     size_type utf_i = utf8_byte_offset(_string.c_str(), i);
00203     if (utf_i != npos) {
00204       // if the offset is not npos, find a proper length for 'n'
00205       size_type utf_n = utf8_byte_offset(_string.data() + utf_i, n,
00206            _string.size() - utf_i);
00207       _string.erase(utf_i, utf_n);
00208     }
00209   } else
00210     _string.erase(i, n);
00211 
00212   return *this;
00213 }

ustring::size_type otk::ustring::max_size   const
 

Definition at line 183 of file ustring.cc.

References _string.

00184 {
00185   return _string.max_size();
00186 }

ustring & otk::ustring::operator+= char    c
 

Definition at line 158 of file ustring.cc.

References _string.

00159 {
00160   _string += c;
00161   return *this;
00162 }

ustring & otk::ustring::operator+= const char *    src
 

Definition at line 152 of file ustring.cc.

References _string.

00153 {
00154   _string += src;
00155   return *this;
00156 }

ustring & otk::ustring::operator+= const ustring &    src
 

Definition at line 145 of file ustring.cc.

References _string, and _utf8.

00146 {
00147   assert(_utf8 == src._utf8);
00148   _string += src._string;
00149   return *this;
00150 }

ustring & otk::ustring::operator= const ustring &    other
 

Definition at line 128 of file ustring.cc.

References _string, and _utf8.

00129 {
00130   _string = other._string;
00131   _utf8 = other._utf8;
00132   return *this;
00133 }

bool otk::ustring::operator== const char *    other const
 

Definition at line 242 of file ustring.cc.

References _string.

00243 {
00244   return _string == other;
00245 }

bool otk::ustring::operator== const std::string &    other const
 

Definition at line 237 of file ustring.cc.

References _string.

00238 {
00239   return _string == other;
00240 }

bool otk::ustring::operator== const ustring &    other const
 

Definition at line 232 of file ustring.cc.

References _string, and _utf8.

00233 {
00234   return _string == other._string && _utf8 == other._utf8;
00235 }

ustring::value_type otk::ustring::operator[] size_type    i const
 

Definition at line 227 of file ustring.cc.

References _string, otk::utf8_get_char(), and otk::utf8_offset_to_ptr().

00228 {
00229   return utf8_get_char(utf8_offset_to_ptr(_string.data(), i));
00230 }

void otk::ustring::resize size_type    n,
char    c = '\0'
 

Definition at line 215 of file ustring.cc.

References _string, erase(), size(), and size_type.

Referenced by ob::LabelWidget::renderForeground(), otk::Label::renderForeground(), and otk::FocusLabel::renderForeground().

00216 {
00217   if (_utf8) {
00218     const size_type size_now = size();
00219     if(n < size_now)
00220       erase(n, npos);
00221     else if(n > size_now)
00222       _string.append(n - size_now, c);
00223   } else
00224     _string.resize(n, c);
00225 }

void otk::ustring::setUtf8 bool    utf8
 

Definition at line 262 of file ustring.cc.

References _utf8.

00263 {
00264   _utf8 = utf8;
00265 }

ustring::size_type otk::ustring::size   const
 

Definition at line 164 of file ustring.cc.

References _string, and otk::utf8_ptr_to_offset().

Referenced by ob::Frame::adjustSize(), ob::LabelWidget::renderForeground(), otk::Label::renderForeground(), otk::FocusLabel::renderForeground(), and resize().

00165 {
00166   if (_utf8) {
00167     const char *const pdata = _string.data();
00168     return utf8_ptr_to_offset(pdata, pdata + _string.size());
00169   } else
00170     return _string.size();
00171 }

bool otk::ustring::utf8   const
 

Definition at line 257 of file ustring.cc.

References _utf8.

Referenced by otk::RenderControl::drawString(), otk::Font::measureString(), and otk::Property::set().

00258 {
00259   return _utf8;
00260 }


Member Data Documentation

std::string otk::ustring::_string [private]
 

Definition at line 104 of file ustring.hh.

Referenced by bytes(), c_str(), capacity(), clear(), data(), empty(), erase(), max_size(), operator+=(), operator=(), operator==(), operator[](), resize(), and size().

bool otk::ustring::_utf8 [private]
 

Definition at line 105 of file ustring.hh.

Referenced by operator+=(), operator=(), operator==(), setUtf8(), and utf8().

const size_type otk::ustring::npos = std::string::npos [static]
 

Definition at line 118 of file ustring.hh.

Referenced by erase().


The documentation for this class was generated from the following files:
Generated on Tue Feb 4 23:00:30 2003 for Openbox by doxygen1.3-rc2