Changeset 15655 for gsdl/trunk/lib/dbclass.cpp
- Timestamp:
- 2008-05-22T16:44:51+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/lib/dbclass.cpp
r15652 r15655 26 26 #include "dbclass.h" 27 27 #include "OIDtools.h" 28 #include "unitool.h" 28 29 29 30 … … 36 37 text_t data; 37 38 return getkeydata (key, data); 39 } 40 41 42 // May be overwritten by subclasses; returns true on success 43 bool dbclass::getinfo (const text_t& key, infodbclass &info) 44 { 45 text_t data; 46 if (!getkeydata(key, data)) return false; 47 48 // Use getinfoline() to parse the data value into the infodbclass object 49 text_t::iterator data_iterator = data.begin(); 50 text_t ikey, ivalue; 51 info.clear(); 52 while (getinfoline(data_iterator, data.end(), ikey, ivalue)) 53 { 54 info.addinfo(ikey, ivalue); 55 } 56 57 return true; 58 } 59 60 61 // returns true on success 62 bool dbclass::getinfoline (text_t::iterator &here, text_t::iterator end, 63 text_t &key, text_t &value) 64 { 65 key.clear(); 66 value.clear(); 67 68 // ignore white space 69 while (here != end && is_unicode_space (*here)) ++here; 70 71 // get the '<' 72 if (here == end || *here != '<') return false; 73 ++here; 74 75 // get the key 76 while (here != end && *here != '>') { 77 key.push_back(*here); 78 ++here; 79 } 80 81 // get the '>' 82 if (here == end || *here != '>') return false; 83 ++here; 84 85 // get the value 86 while (here != end && *here != '\n') { 87 if (*here == '\\') { 88 // found escape character 89 ++here; 90 if (here != end) { 91 if (*here == 'n') value.push_back ('\n'); 92 else if (*here == 'r') value.push_back ('\r'); 93 else value.push_back(*here); 94 } 95 96 } else { 97 // a normal character 98 value.push_back(*here); 99 } 100 101 ++here; 102 } 103 104 return true; 105 } 106 107 108 // returns true on success 109 bool dbclass::setinfo (const text_t &key, const infodbclass &info) 110 { 111 text_t subkey; 112 text_t data; 113 114 // get all the keys and values 115 infodbclass::const_iterator info_here = info.begin(); 116 infodbclass::const_iterator info_end = info.end(); 117 while (info_here != info_end) { 118 // add the key 119 subkey.clear(); 120 subkey.push_back('<'); 121 text_t::const_iterator subkey_here = (*info_here).first.begin(); 122 text_t::const_iterator subkey_end = (*info_here).first.end(); 123 while (subkey_here != subkey_end) { 124 if (*subkey_here == '>') { 125 subkey.push_back('\\'); subkey.push_back('>'); 126 } else if (*subkey_here == '\n') { 127 subkey.push_back('\\'); subkey.push_back('n'); 128 } else if (*subkey_here == '\r') { 129 subkey.push_back('\\'); subkey.push_back('r'); 130 } else if (*subkey_here == '\\') { 131 subkey.push_back('\\'); subkey.push_back('\\'); 132 } else { 133 subkey.push_back (*subkey_here); 134 } 135 ++subkey_here; 136 } 137 subkey.push_back('>'); 138 139 // add the values 140 text_tarray::const_iterator subvalue_here = (*info_here).second.begin(); 141 text_tarray::const_iterator subvalue_end = (*info_here).second.end(); 142 while (subvalue_here != subvalue_end) { 143 data += subkey; 144 145 text_t::const_iterator thissubvalue_here = (*subvalue_here).begin(); 146 text_t::const_iterator thissubvalue_end = (*subvalue_here).end(); 147 while (thissubvalue_here != thissubvalue_end) { 148 if (*thissubvalue_here == '>') { 149 data.push_back('\\'); data.push_back('>'); 150 } else if (*thissubvalue_here == '\n') { 151 data.push_back('\\'); data.push_back('n'); 152 } else if (*thissubvalue_here == '\r') { 153 data.push_back('\\'); data.push_back('r'); 154 } else if (*thissubvalue_here == '\\') { 155 data.push_back('\\'); data.push_back('\\'); 156 } else { 157 data.push_back (*thissubvalue_here); 158 } 159 160 ++thissubvalue_here; 161 } 162 163 data.push_back('\n'); 164 ++subvalue_here; 165 } 166 167 ++info_here; 168 } 169 170 return setkeydata(key, data); 38 171 } 39 172
Note:
See TracChangeset
for help on using the changeset viewer.