]> Dogcows Code - chaz/openbox/blobdiff - otk/ustring.hh
almost done the ustring conversion
[chaz/openbox] / otk / ustring.hh
index 5d011cfc8837a21e196b789168d91602db4a33e4..647bee86f641b69c99b24a5c9b0a80da14e23a70 100644 (file)
@@ -7,6 +7,7 @@
 */
 
 extern "C" {
+/*
 #ifdef HAVE_STDINT_H
 #  include <stdint.h>
 #else
@@ -14,12 +15,23 @@ extern "C" {
 #    include <sys/types.h>
 #  endif
 #endif
+*/
 }
 
 #include <string>
 
 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,
@@ -32,11 +44,7 @@ const char g_utf8_skip[256] = {
   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
 };
 
-#ifdef HAVE_STDINT_H
-typedef uint32_t unichar;
-#else
-typedef u_int32_t unichar;
-#endif
+#endif // DOXYGEN_IGNORE
 
 //! The iterator type for ustring
 /*!
@@ -49,20 +57,22 @@ typedef u_int32_t unichar;
   write operation would invalidate all other iterators pointing into the same
   string.
 */
+/*
 template <class T>
 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 value_type                        reference;
   typedef void                              pointer;
 
   inline ustring_Iterator() {}
   inline ustring_Iterator(const ustring_Iterator<std::string::iterator>&
                          other) : _pos(other.base()) {}
 
+
   inline value_type operator*() const {
     // get a unicode character from the iterator's position
 
@@ -86,6 +96,7 @@ public:
     return result;
   }
 
+  
   inline ustring_Iterator<T> &     operator++() {
     pos_ += g_utf8_skip[static_cast<unsigned char>(*pos_)];
     return *this;
@@ -101,9 +112,11 @@ public:
 private:
   T _pos;
 };
+*/
 
-//! This class provides a simple wrapper to a std::string that is encoded as
-//! UTF-8.
+//! 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 <b>not</b> handle extended 8-bit ASCII charsets like
   ISO-8859-1.
@@ -116,17 +129,18 @@ private:
 */
 class ustring {
   std::string _string;
-
+  bool _utf8;
+  
 public:
   typedef std::string::size_type                        size_type;
   typedef std::string::difference_type                  difference_type;
 
-  typedef unichar                                       value_type;
-  typedef unichar &                                     reference;
-  typedef const unichar &                               const_reference;
+  //typedef unichar                                       value_type;
+  //typedef unichar &                                     reference;
+  //typedef const unichar &                               const_reference;
 
-  typedef ustring_Iterator<std::string::iterator>       iterator;
-  typedef ustring_Iterator<std::string::const_iterator> const_iterator;
+  //typedef ustring_Iterator<std::string::iterator>       iterator;
+  //typedef ustring_Iterator<std::string::const_iterator> const_iterator;
 
   static const size_type npos = std::string::npos;
 
@@ -138,9 +152,40 @@ public:
   ustring(const ustring& other);
   ustring& operator=(const ustring& other);
   ustring(const std::string& src);
-  ustring::ustring(const char* src);
+  ustring(const char* src);
+
+  // append to the string
+
+  ustring& operator+=(const ustring& src);
+  ustring& operator+=(const char* src);
+  ustring& operator+=(char c);
+
+  // sizes
+  
+  ustring::size_type size() const;
+  ustring::size_type bytes() const;
+  ustring::size_type capacity() const;
+  ustring::size_type max_size() const;
+  bool empty() const;
+
+  // erase substrings
+
+  void clear();
+  ustring& erase(size_type i, size_type n=npos);
+
+  // change the string's size
+
+  void resize(size_type n, char c='\0');
+  
+  // internal data
+
+  const char* data()  const;
+  const char* c_str() const;
 
+  // encoding
   
+  bool utf8() const;
+  void setUtf8(bool utf8);
 };
 
 }
This page took 0.023639 seconds and 4 git commands to generate.