make getting a list of strings work right

This commit is contained in:
Dana Jansens 2002-06-28 01:43:32 +00:00
parent 578a5cc980
commit e9f582ae97
2 changed files with 9 additions and 9 deletions

View file

@ -434,7 +434,7 @@ bool XAtom::getValue(Window win, Atoms atom, Atoms type,
*/ */
bool XAtom::getValue(Window win, Atoms atom, StringType type, bool XAtom::getValue(Window win, Atoms atom, StringType type,
std::string &value) const { std::string &value) const {
int n = 1; unsigned long n = 1;
StringVect s; StringVect s;
if (getValue(win, atom, type, n, s)) { if (getValue(win, atom, type, n, s)) {
value = s[0]; value = s[0];
@ -444,8 +444,8 @@ bool XAtom::getValue(Window win, Atoms atom, StringType type,
} }
bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements, bool XAtom::getValue(Window win, Atoms atom, StringType type,
StringVect &strings) const { unsigned long &nelements, StringVect &strings) const {
assert(atom >= 0 && atom < NUM_ATOMS); assert(atom >= 0 && atom < NUM_ATOMS);
assert(type >= 0 && type < NUM_STRING_TYPE); assert(type >= 0 && type < NUM_STRING_TYPE);
assert(win != None); assert(_atoms[atom] != None); assert(win != None); assert(_atoms[atom] != None);
@ -463,22 +463,22 @@ bool XAtom::getValue(Window win, Atoms atom, StringType type, int &nelements,
if (!getValue(win, _atoms[atom], t, elements, &value, 8) || elements < 1) if (!getValue(win, _atoms[atom], t, elements, &value, 8) || elements < 1)
return false; return false;
std::string s(reinterpret_cast<char *>(value)); std::string s(reinterpret_cast<char *>(value), elements);
delete [] value; delete [] value;
std::string::const_iterator it = s.begin(), end = s.end(); std::string::const_iterator it = s.begin(), end = s.end();
int num = 0; unsigned long num = 0;
while(num < nelements) { while(num < nelements) {
std::string::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 it = std::find(tmp, end, '\0'); // look for null between tmp and end
strings.push_back(std::string(tmp, it)); // s[tmp:it) strings.push_back(std::string(tmp, it)); // s[tmp:it)
if (it == end) if (it == end) break;
break;
++it; ++it;
if (it == end) break;
++num; ++num;
} }
nelements = elements; nelements = num;
return true; return true;
} }

View file

@ -207,7 +207,7 @@ public:
bool getValue(Window win, Atoms atom, StringType type, bool getValue(Window win, Atoms atom, StringType type,
std::string &value) const; std::string &value) const;
bool getValue(Window win, Atoms atom, StringType type, bool getValue(Window win, Atoms atom, StringType type,
int &nelements, StringVect &strings) const; unsigned long &nelements, StringVect &strings) const;
void eraseValue(Window win, Atoms atom) const; void eraseValue(Window win, Atoms atom) const;