From ac847aedd890280f5f31f5f65e7b7b5e8ca5bf3c Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Sat, 8 Jun 2024 02:30:07 +0300 Subject: [PATCH] [db2] Better trim. --- src/common/db2.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/common/db2.h b/src/common/db2.h index 1071d74..3902a7b 100644 --- a/src/common/db2.h +++ b/src/common/db2.h @@ -330,11 +330,13 @@ struct db2 { // converts string to utf8 // filters out values with empty name "" auto to_map(int cp) const { - auto prepare_string = [&](auto &&in) { + auto prepare_string = [&](auto &&in, bool trim = false) { auto s = str2utf8(in, cp); // 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); + if (trim) { + boost::trim(s); + } return s; }; @@ -377,7 +379,10 @@ struct db2 { jv[fn] = *(float *)p; break; case db2::field_type::string: - jv[fn] = boost::trim_copy(prepare_string((const char *)p)); // trim field value + // also trim 'NAME' field value + jv[fn] = prepare_string((const char *)p, fn == "NAME"s); + // we cannot trim, some strings should end (and start?) with space + //jv[fn] = boost::trim_copy(prepare_string((const char *)p)); // trim field value break; default: throw std::logic_error{"bad type"};