diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-20 10:46:26 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-20 10:46:26 +0000 |
commit | 8994ac249f4cd46a0285d7bd9af19305fbdadb54 (patch) | |
tree | 313c4b4a2aed559870b457d33855d499255a1fb7 /searchlib | |
parent | bbfdba2465db7cc8d7ef0b44bc0d4fd5d152036b (diff) |
Handle leading whitespace and test behaviour.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/fef/properties/properties_test.cpp | 41 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/fef/indexproperties.cpp | 7 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/fef/properties.cpp | 16 |
3 files changed, 51 insertions, 13 deletions
diff --git a/searchlib/src/tests/fef/properties/properties_test.cpp b/searchlib/src/tests/fef/properties/properties_test.cpp index 5e18c41b40a..c8073739b3e 100644 --- a/searchlib/src/tests/fef/properties/properties_test.cpp +++ b/searchlib/src/tests/fef/properties/properties_test.cpp @@ -10,9 +10,8 @@ using namespace search::fef::indexproperties; struct CopyVisitor : public IPropertiesVisitor { Properties &dst; - CopyVisitor(Properties &p) : dst(p) {} - virtual void visitProperty(const Property::Value &key, - const Property &values) override + explicit CopyVisitor(Properties &p) noexcept : dst(p) {} + void visitProperty(const Property::Value &key, const Property &values) override { for (uint32_t i = 0; i < values.size(); ++i) { dst.add(key, values.getAt(i)); @@ -590,5 +589,41 @@ TEST("test query feature type properties") EXPECT_EQUAL("", type::QueryFeature::lookup(p, "bar")); } +TEST("test integer lookup") +{ + EXPECT_EQUAL(matching::NumThreadsPerSearch::NAME, vespalib::string("vespa.matching.numthreadspersearch")); + EXPECT_EQUAL(matching::NumThreadsPerSearch::DEFAULT_VALUE, std::numeric_limits<uint32_t>::max()); + { + Properties p; + p.add("vespa.matching.numthreadspersearch", "50"); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), 50u); + } + { + Properties p; + p.add("vespa.matching.numthreadspersearch", "50 "); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), 50u); + } + { + Properties p; + p.add("vespa.matching.numthreadspersearch", " 50"); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), 50u); + } + { + Properties p; + p.add("vespa.matching.numthreadspersearch", " "); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), matching::NumThreadsPerSearch::DEFAULT_VALUE); + } + { + Properties p; + p.add("vespa.matching.numthreadspersearch", "50x"); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), 50u); + } + { + Properties p; + p.add("vespa.matching.numthreadspersearch", "x"); + EXPECT_EQUAL(matching::NumThreadsPerSearch::lookup(p), matching::NumThreadsPerSearch::DEFAULT_VALUE); + } +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp index 9267913d275..659c7d2c8cc 100644 --- a/searchlib/src/vespa/searchlib/fef/indexproperties.cpp +++ b/searchlib/src/vespa/searchlib/fef/indexproperties.cpp @@ -52,8 +52,11 @@ lookupUint32(const Properties &props, const vespalib::string &name, uint32_t def Property p = props.lookup(name); uint32_t value(defaultValue); if (p.found()) { - const auto & s = p.get(); - std::from_chars(s.c_str(), s.c_str() + s.size(), value); + const auto & valS = p.get(); + const char * start = valS.c_str(); + const char * end = start + valS.size(); + while (isspace(start[0]) && start != end) { start++; } + std::from_chars(start, end, value); } return value; } diff --git a/searchlib/src/vespa/searchlib/fef/properties.cpp b/searchlib/src/vespa/searchlib/fef/properties.cpp index bd4795fcc5a..6134807fa60 100644 --- a/searchlib/src/vespa/searchlib/fef/properties.cpp +++ b/searchlib/src/vespa/searchlib/fef/properties.cpp @@ -25,7 +25,7 @@ uint32_t Properties::rawHash(const void *buf, uint32_t len) noexcept { uint32_t res = 0; - unsigned const char *pt = (unsigned const char *) buf; + auto *pt = (unsigned const char *) buf; unsigned const char *end = pt + len; while (pt < end) { res = (res << 7) + (res >> 25) + *pt++; @@ -52,7 +52,7 @@ Properties::add(vespalib::stringref key, vespalib::stringref value) { if (!key.empty()) { Value & v = _data[key]; - v.push_back(value); + v.emplace_back(value); ++_numValues; } return *this; @@ -162,20 +162,20 @@ Property Properties::lookup(vespalib::stringref key) const noexcept { if (key.empty()) { - return Property(); + return {}; } auto node = _data.find(key); if (node == _data.end()) { - return Property(); + return {}; } - return Property(node->second); + return {node->second}; } Property Properties::lookup(vespalib::stringref namespace1, vespalib::stringref key) const noexcept { if (namespace1.empty() || key.empty()) { - return Property(); + return {}; } vespalib::string fullKey(namespace1); fullKey.append('.').append(key); @@ -187,7 +187,7 @@ Property Properties::lookup(vespalib::stringref namespace1, vespalib::stringref key) const noexcept { if (namespace1.empty() || namespace2.empty() || key.empty()) { - return Property(); + return {}; } vespalib::string fullKey(namespace1); fullKey.append('.').append(namespace2).append('.').append(key); @@ -200,7 +200,7 @@ Property Properties::lookup(vespalib::stringref namespace1, vespalib::stringref key) const noexcept { if (namespace1.empty() || namespace2.empty() || namespace3.empty() || key.empty()) { - return Property(); + return {}; } vespalib::string fullKey(namespace1); fullKey.append('.').append(namespace2).append('.').append(namespace3).append('.').append(key); |