| … | … | @@ -184,6 +184,48 @@ ValuePtr Sexpr::decode_value(const std::string& stv, size_t& pos) |
| 184 | 184 | return valueserver().create(vtype, fv); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | // BoolValue can be either "(BoolValue 1 0 1 ...)" or "(BoolValue #x...)" |
| 188 | if (nameserver().isA(vtype, BOOL_VALUE)) |
| 189 | { |
| 190 | std::vector<bool> bv; |
| 191 | vos = stv.find_first_not_of(" \n\t", vos); |
| 192 | |
| 193 | // Handle hex format: (BoolValue #x...) |
| 194 | if (vos < totlen and stv[vos] == '#' and vos+1 < totlen and stv[vos+1] == 'x') |
| 195 | { |
| 196 | vos += 2; // Skip "#x" |
| 197 | // Parse hex digits until we hit ')' |
| 198 | while (vos < totlen and stv[vos] != ')') |
| 199 | { |
| 200 | char c = stv[vos]; |
| 201 | if (std::isxdigit(c)) |
| 202 | { |
| 203 | int nibble = (c >= '0' and c <= '9') ? c - '0' : |
| 204 | (c >= 'a' and c <= 'f') ? c - 'a' + 10 : |
| 205 | (c >= 'A' and c <= 'F') ? c - 'A' + 10 : 0; |
| 206 | // Each hex digit represents 4 bits |
| 207 | for (int bit = 3; bit >= 0; bit--) |
| 208 | bv.push_back((nibble >> bit) & 1); |
| 209 | } |
| 210 | vos++; |
| 211 | } |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | // Handle individual bits: (BoolValue 1 0 1 ...) |
| 216 | while (vos < totlen and stv[vos] != ')') |
| 217 | { |
| 218 | vos = stv.find_first_not_of(" \n\t", vos); |
| 219 | if (vos >= totlen or stv[vos] == ')') break; |
| 220 | if (stv[vos] == '0') bv.push_back(false); |
| 221 | else if (stv[vos] == '1') bv.push_back(true); |
| 222 | vos++; |
| 223 | } |
| 224 | } |
| 225 | pos = vos + 1; |
| 226 | return valueserver().create(vtype, bv); |
| 227 | } |
| 228 | |
| 187 | 229 | // Unescape escaped quotes |
| 188 | 230 | if (nameserver().isA(vtype, STRING_VALUE)) |
| 189 | 231 | { |