]> Dogcows Code - chaz/openbox/blobdiff - otk/property.cc
ustring seems to be working! yay!
[chaz/openbox] / otk / property.cc
index 77bdfb0382fefff651a8d5e7ff644174982b54db..ab99cd8929d0de47470ad2c38d66eaa6e7c2431a 100644 (file)
@@ -163,7 +163,7 @@ Property::~Property()
  */
 Atom Property::create(const char *name) const
 {
-  Atom a = XInternAtom(Display::display, name, false);
+  Atom a = XInternAtom(Display::display, name, False);
   assert(a);
   return a;
 }
@@ -196,7 +196,7 @@ void Property::set(Window win, Atoms atom, Atoms type,
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   set(win, _atoms[atom], _atoms[type],
-           reinterpret_cast<unsigned char*>(&value), 32, 1, false);
+           reinterpret_cast<unsigned char*>(&value), 32, 1, False);
 }
 
 
@@ -209,7 +209,7 @@ void Property::set(Window win, Atoms atom, Atoms type,
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_ATOMS);
   set(win, _atoms[atom], _atoms[type],
-      reinterpret_cast<unsigned char*>(value), 32, elements, false);
+      reinterpret_cast<unsigned char*>(value), 32, elements, False);
 }
 
 
@@ -217,20 +217,21 @@ void Property::set(Window win, Atoms atom, Atoms type,
  * Set an string property value on a window.
  */
 void Property::set(Window win, Atoms atom, StringType type,
-                          const userstring &value) const
+                          const ustring &value) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
   
   Atom t;
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
-  default: assert(false); return; // unhandled StringType
+  case ascii: t = _atoms[Atom_String]; assert(!value.utf8()); break;
+  case utf8:  t = _atoms[Atom_Utf8]; assert(value.utf8()); break;
+  default: assert(False); return; // unhandled StringType
   }
+  
   set(win, _atoms[atom], t,
       reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
-      8, value.size() + 1, false); // add 1 to the size to include the null
+      8, value.size() + 1, False); // add 1 to the size to include the null
 }
 
 
@@ -238,35 +239,39 @@ void Property::set(Window win, Atoms atom, StringType type,
  * Set an array of string property values on a window.
  */
 void Property::set(Window win, Atoms atom, StringType type,
-                     const userstring::vector &strings) const
+                     const StringVect &strings) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
 
   Atom t;
+  bool u; // utf8 encoded?
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; break;
-  case utf8:  t = _atoms[Atom_Utf8]; break;
-  default: assert(false); return; // unhandled StringType
+  case ascii: t = _atoms[Atom_String]; u = false; break;
+  case utf8:  t = _atoms[Atom_Utf8];   u = true;  break;
+  default: assert(False); return; // unhandled StringType
   }
 
-  std::string value;
+  ustring value;
 
-  userstring::vector::const_iterator it = strings.begin();
-  const userstring::vector::const_iterator end = strings.end();
-  for (; it != end; ++it)
-      value += *it + '\0';
+  StringVect::const_iterator it = strings.begin();
+  const StringVect::const_iterator end = strings.end();
+  for (; it != end; ++it) {
+    assert(it->utf8() == u); // the ustring is encoded correctly?
+    value += *it;
+    value += '\0';
+  }
 
   set(win, _atoms[atom], t,
       reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
-      8, value.size(), false);
+      8, value.size(), False);
 }
 
 
 /*
  * Internal get function used by all of the typed get functions.
  * Gets an property's value from a window.
- * Returns true if the property was successfully retrieved; false if the
+ * Returns True if the property was successfully retrieved; False if the
  * property did not exist on the window, or has a different type/size format
  * than the user tried to retrieve.
  */
@@ -283,11 +288,11 @@ bool Property::get(Window win, Atom atom, Atom type,
   unsigned long ret_bytes;
   int result;
   unsigned long maxread = *nelements;
-  bool ret = false;
+  bool ret = False;
 
   // try get the first element
   result = XGetWindowProperty(Display::display, win, atom, 0l, 1l,
-                              false, AnyPropertyType, &ret_type, &ret_size,
+                              False, AnyPropertyType, &ret_type, &ret_size,
                               nelements, &ret_bytes, &c_val);
   ret = (result == Success && ret_type == type && ret_size == size &&
          *nelements > 0);
@@ -305,7 +310,7 @@ bool Property::get(Window win, Atom atom, Atom type,
       if (remain > size/8 * (signed)maxread) // dont get more than the max
         remain = size/8 * (signed)maxread;
       result = XGetWindowProperty(Display::display, win, atom, 0l,
-                                  remain, false, type, &ret_type, &ret_size,
+                                  remain, False, type, &ret_type, &ret_size,
                                   nelements, &ret_bytes, &c_val);
       ret = (result == Success && ret_type == type && ret_size == size &&
              ret_bytes == 0);
@@ -352,10 +357,10 @@ bool Property::get(Window win, Atoms atom, Atoms type,
   unsigned long num = 1;
   if (! get(win, _atoms[atom], _atoms[type], &num,
                  reinterpret_cast<unsigned char **>(&temp), 32))
-    return false;
+    return False;
   *value = temp[0];
   delete [] temp;
-  return true;
+  return True;
 }
 
 
@@ -363,25 +368,21 @@ bool Property::get(Window win, Atoms atom, Atoms type,
  * Gets an string property's value from a window.
  */
 bool Property::get(Window win, Atoms atom, StringType type,
-                     userstring *value) const
+                   ustring *value) const
 {
   unsigned long n = 1;
-  userstring::vector s;
+  StringVect s;
+
   if (get(win, atom, type, &n, &s)) {
     *value = s[0];
-    switch (type) {
-    case ascii: value->setUtf8(false); break;
-    case utf8:  value->setUtf8(true); break;
-    default: assert(false); return false; // unhandled StringType
-    }
-    return true;
+    return True;
   }
-  return false;
+  return False;
 }
 
 
 bool Property::get(Window win, Atoms atom, StringType type,
-                   unsigned long *nelements, userstring::vector *strings) const
+                   unsigned long *nelements, StringVect *strings) const
 {
   assert(atom >= 0 && atom < NUM_ATOMS);
   assert(type >= 0 && type < NUM_STRING_TYPE);
@@ -389,27 +390,28 @@ bool Property::get(Window win, Atoms atom, StringType type,
   assert(*nelements > 0);
 
   Atom t;
-  bool isutf8;
+  bool u; // utf8 encoded?
   switch (type) {
-  case ascii: t = _atoms[Atom_String]; isutf8 = false; break;
-  case utf8:  t = _atoms[Atom_Utf8];   isutf8 = true; break;
-  default: assert(false); return false; // unhandled StringType
+  case ascii: t = _atoms[Atom_String]; u = false; break;
+  case utf8:  t = _atoms[Atom_Utf8];   u = true;  break;
+  default: assert(False); return False; // unhandled StringType
   }
   
   unsigned char *value;
   unsigned long elements = (unsigned) -1;
   if (!get(win, _atoms[atom], t, &elements, &value, 8) || elements < 1)
-    return false;
+    return False;
 
-  userstring s(reinterpret_cast<char *>(value), elements, isutf8);
+  std::string s(reinterpret_cast<char *>(value), elements);
   delete [] value;
 
-  userstring::const_iterator it = s.begin(), end = s.end();
+  std::string::const_iterator it = s.begin(), end = s.end();
   unsigned long num = 0;
   while(num < *nelements) {
-    userstring::const_iterator tmp = it;  // current string.begin()
+    std::string::const_iterator tmp = it; // current string.begin()
     it = std::find(tmp, end, '\0');       // look for null between tmp and end
-    strings->push_back(userstring(tmp, it, isutf8));   // s[tmp:it)
+    strings->push_back(std::string(tmp, it));   // s[tmp:it)
+    if (!u) strings->back().setUtf8(false);
     ++num;
     if (it == end) break;
     ++it;
@@ -418,7 +420,7 @@ bool Property::get(Window win, Atoms atom, StringType type,
 
   *nelements = num;
 
-  return true;
+  return True;
 }
 
 
This page took 0.031542 seconds and 4 git commands to generate.