]> Dogcows Code - chaz/openbox/blobdiff - otk/ustring.cc
provide the strut for the frame's size instead of an area rect
[chaz/openbox] / otk / ustring.cc
index b721089e5b28f30b18e14e2f6305196b33e647a2..7ac89bf72759ee351754ef88060bd96d51cbecdb 100644 (file)
@@ -14,6 +14,18 @@ namespace otk {
 
 // helper functions
 
+// The number of bytes to skip to find the next character in the string
+static const char 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
+};
+
 // takes a pointer into a utf8 string and returns a unicode character for the
 // first character at the pointer
 unichar utf8_get_char (const char *p)
@@ -41,7 +53,7 @@ static ustring::size_type utf8_ptr_to_offset(const char *str, const char *pos)
   ustring::size_type offset = 0;
 
   while (str < pos) {
-    str += utf8_skip[*str];
+    str += utf8_skip[static_cast<unsigned char>(*str)];
     offset++;
   }
 
@@ -52,7 +64,7 @@ static ustring::size_type utf8_ptr_to_offset(const char *str, const char *pos)
 const char *utf8_offset_to_ptr(const char *str, ustring::size_type offset)
 {
   while (offset--)
-    str += utf8_skip[*str];
+    str += utf8_skip[static_cast<unsigned char>(*str)];
   return str;
 }
 
@@ -69,7 +81,7 @@ ustring::size_type utf8_byte_offset(const char* str, ustring::size_type offset)
     if(*p == '\0')
       return ustring::npos;
 
-    p += utf8_skip[*p];
+    p += utf8_skip[static_cast<unsigned char>(*p)];
   }
 
   return (p - str);
@@ -90,7 +102,7 @@ ustring::size_type utf8_byte_offset(const char* str, ustring::size_type offset,
     if(p >= pend)
       return ustring::npos;
 
-    p += utf8_skip[*p];
+    p += utf8_skip[static_cast<unsigned char>(*p)];
   }
 
   return (p - str);
@@ -99,7 +111,8 @@ ustring::size_type utf8_byte_offset(const char* str, ustring::size_type offset,
 
 // ustring methods
 
-ustring::ustring()
+ustring::ustring(bool utf8)
+  : _utf8(utf8)
 {
 }
 
@@ -119,13 +132,13 @@ ustring& ustring::operator=(const ustring& other)
   return *this;
 }
 
-ustring::ustring(const std::string& src)
-  : _string(src), _utf8(true)
+ustring::ustring(const std::string& src, bool utf8)
+  : _string(src), _utf8(utf8)
 {
 }
 
-ustring::ustring(const char* src)
-  : _string(src), _utf8(true)
+ustring::ustring(const char* src, bool utf8)
+  : _string(src), _utf8(utf8)
 {
 }
 
This page took 0.024802 seconds and 4 git commands to generate.