Do not trim value names for now. There are such error fields in aim2 db.

This commit is contained in:
lzwdgc 2024-04-02 14:38:48 +03:00
parent 8954b11c95
commit 8e4c4cfd64

View file

@ -183,6 +183,7 @@ struct db2 {
auto begin(this auto &&d) {return d.m.begin();} auto begin(this auto &&d) {return d.m.begin();}
auto end(this auto &&d) {return d.m.end();} auto end(this auto &&d) {return d.m.end();}
bool empty() const { return m.empty(); }
auto &operator[](this auto &&d, const std::string &s) { auto &operator[](this auto &&d, const std::string &s) {
return d.m[s]; return d.m[s];
} }
@ -281,12 +282,14 @@ struct db2 {
} }
}; };
// converts string to utf8, trims them // converts string to utf8
// filters out values with empty name "" // filters out values with empty name ""
auto to_map() const { auto to_map() const {
auto prepare_string = [](auto &&in) { auto prepare_string = [](auto &&in) {
auto s = str2utf8(in); auto s = str2utf8(in);
boost::trim(s); // we have some erroneous table values (records) with spaces
// we can trim only field values, but don't do it at the moment
//boost::trim(s);
return s; return s;
}; };
@ -311,6 +314,7 @@ struct db2 {
throw std::logic_error{"unknown field"}; throw std::logic_error{"unknown field"};
} }
auto fn = prepare_string(f->name); auto fn = prepare_string(f->name);
boost::trim(fn); // trim field name
if (jv.contains(fn)) { if (jv.contains(fn)) {
// we analyze such cases manually // we analyze such cases manually
throw std::logic_error{"duplicate field: "s + fn}; throw std::logic_error{"duplicate field: "s + fn};
@ -323,7 +327,7 @@ struct db2 {
jv[fn] = *(float *)p; jv[fn] = *(float *)p;
break; break;
case db2::field_type::string: case db2::field_type::string:
jv[fn] = prepare_string((const char *)p); jv[fn] = boost::trim_copy(prepare_string((const char *)p)); // trim field value
break; break;
default: default:
throw std::logic_error{"bad type"}; throw std::logic_error{"bad type"};