X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fustring.hh;h=0031e1c5b888db645c7ee397038f3f62d8ade854;hb=dca8c61a91cab29128a72f252b70f4bd9f7786ff;hp=647bee86f641b69c99b24a5c9b0a80da14e23a70;hpb=ef02a0c8ae65f169157c90064a335303e964a4c1;p=chaz%2Fopenbox diff --git a/otk/ustring.hh b/otk/ustring.hh index 647bee86..0031e1c5 100644 --- a/otk/ustring.hh +++ b/otk/ustring.hh @@ -7,7 +7,7 @@ */ extern "C" { -/* + #ifdef HAVE_STDINT_H # include #else @@ -15,34 +15,24 @@ extern "C" { # include # endif #endif -*/ + } #include namespace otk { -/* + #ifdef HAVE_STDINT_H typedef uint32_t unichar; #else typedef u_int32_t unichar; #endif -*/ + #ifndef DOXYGEN_IGNORE -//! The number of bytes to skip to find the next character in the string -const char g_utf8_skip[256] = { - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1 -}; +unichar utf8_get_char(const char *p); #endif // DOXYGEN_IGNORE @@ -57,43 +47,26 @@ const char g_utf8_skip[256] = { write operation would invalidate all other iterators pointing into the same string. */ -/* + template class ustring_Iterator { public: typedef std::bidirectional_iterator_tag iterator_category; - //typedef unichar value_type; + typedef unichar value_type; typedef std::string::difference_type difference_type; //typedef value_type reference; typedef void pointer; - + inline ustring_Iterator() {} inline ustring_Iterator(const ustring_Iterator& other) : _pos(other.base()) {} inline value_type operator*() const { - // get a unicode character from the iterator's position - // get an iterator to the internal string std::string::const_iterator pos = _pos; - - unichar result = static_cast(*pos); - - // if its not a 7-bit ascii character - if((result & 0x80) != 0) { - // len is the number of bytes this character takes up in the string - unsigned char len = g_utf8_skip[result]; - result &= 0x7F >> len; - - while(--len != 0) { - result <<= 6; - result |= static_cast(*++pos) & 0x3F; - } - } - - return result; + return utf8_get_char(&(*pos)); } @@ -112,7 +85,7 @@ public: private: T _pos; }; -*/ + //! 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 @@ -135,7 +108,7 @@ public: typedef std::string::size_type size_type; typedef std::string::difference_type difference_type; - //typedef unichar value_type; + typedef unichar value_type; //typedef unichar & reference; //typedef const unichar & const_reference; @@ -144,15 +117,15 @@ public: static const size_type npos = std::string::npos; - ustring(); + ustring(bool utf8 = true); ~ustring(); // make new strings ustring(const ustring& other); ustring& operator=(const ustring& other); - ustring(const std::string& src); - ustring(const char* src); + ustring(const std::string& src, bool utf8 = true); + ustring(const char* src, bool utf8 = true); // append to the string @@ -176,7 +149,18 @@ public: // change the string's size void resize(size_type n, char c='\0'); + + // extract characters + // No reference return; use replace() to write characters. + value_type operator[](size_type i) const; + + // compare strings + + bool operator==(const ustring &other) const; + bool operator==(const std::string &other) const; + bool operator==(const char *other) const; + // internal data const char* data() const;