Changeset 15655 for gsdl/trunk/lib/gdbmclass.cpp
- Timestamp:
- 2008-05-22T16:44:51+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/gdbmclass.cpp
r15652 r15655 116 116 117 117 // returns true on success 118 bool gdbmclass::getinfo (const text_t& key, infodbclass &info)119 {120 text_t data;121 if (!getkeydata(key, data)) return false;122 123 // Use getinfoline() to parse the data value into the infodbclass object124 text_t::iterator data_iterator = data.begin();125 text_t ikey, ivalue;126 info.clear();127 while (getinfoline(data_iterator, data.end(), ikey, ivalue))128 {129 info.addinfo(ikey, ivalue);130 }131 132 return true;133 }134 135 136 // returns true on success137 118 bool gdbmclass::getkeydata (const text_t& key, text_t &data) 138 119 { … … 181 162 182 163 // returns true on success 183 bool gdbmclass::setinfo (const text_t &key, const infodbclass &info)184 {185 if (gdbmfile == NULL) return false;186 187 text_t subkey;188 text_t data;189 190 // get all the keys and values191 infodbclass::const_iterator info_here = info.begin();192 infodbclass::const_iterator info_end = info.end();193 while (info_here != info_end) {194 // add the key195 subkey.clear();196 subkey.push_back('<');197 text_t::const_iterator subkey_here = (*info_here).first.begin();198 text_t::const_iterator subkey_end = (*info_here).first.end();199 while (subkey_here != subkey_end) {200 if (*subkey_here == '>') {201 subkey.push_back('\\'); subkey.push_back('>');202 } else if (*subkey_here == '\n') {203 subkey.push_back('\\'); subkey.push_back('n');204 } else if (*subkey_here == '\r') {205 subkey.push_back('\\'); subkey.push_back('r');206 } else if (*subkey_here == '\\') {207 subkey.push_back('\\'); subkey.push_back('\\');208 } else {209 subkey.push_back (*subkey_here);210 }211 ++subkey_here;212 }213 subkey.push_back('>');214 215 // add the values216 text_tarray::const_iterator subvalue_here = (*info_here).second.begin();217 text_tarray::const_iterator subvalue_end = (*info_here).second.end();218 while (subvalue_here != subvalue_end) {219 data += subkey;220 221 text_t::const_iterator thissubvalue_here = (*subvalue_here).begin();222 text_t::const_iterator thissubvalue_end = (*subvalue_here).end();223 while (thissubvalue_here != thissubvalue_end) {224 if (*thissubvalue_here == '>') {225 data.push_back('\\'); data.push_back('>');226 } else if (*thissubvalue_here == '\n') {227 data.push_back('\\'); data.push_back('n');228 } else if (*thissubvalue_here == '\r') {229 data.push_back('\\'); data.push_back('r');230 } else if (*thissubvalue_here == '\\') {231 data.push_back('\\'); data.push_back('\\');232 } else {233 data.push_back (*thissubvalue_here);234 }235 236 ++thissubvalue_here;237 }238 239 data.push_back('\n');240 ++subvalue_here;241 }242 243 ++info_here;244 }245 246 return setkeydata(key, data);247 }248 249 250 // returns true on success251 164 bool gdbmclass::setkeydata (const text_t &key, const text_t &data) 252 165 { … … 329 242 return to_uni(nextkey); // convert to unicode 330 243 } 331 332 333 // returns true on success334 bool gdbmclass::getinfoline (text_t::iterator &here, text_t::iterator end,335 text_t &key, text_t &value)336 {337 key.clear();338 value.clear();339 340 // ignore white space341 while (here != end && is_unicode_space (*here)) ++here;342 343 // get the '<'344 if (here == end || *here != '<') return false;345 ++here;346 347 // get the key348 while (here != end && *here != '>') {349 key.push_back(*here);350 ++here;351 }352 353 // get the '>'354 if (here == end || *here != '>') return false;355 ++here;356 357 // get the value358 while (here != end && *here != '\n') {359 if (*here == '\\') {360 // found escape character361 ++here;362 if (here != end) {363 if (*here == 'n') value.push_back ('\n');364 else if (*here == 'r') value.push_back ('\r');365 else value.push_back(*here);366 }367 368 } else {369 // a normal character370 value.push_back(*here);371 }372 373 ++here;374 }375 376 return true;377 }
Note:
See TracChangeset
for help on using the changeset viewer.