Small fixes for review + test

Signed-off-by: Anton Makouski <anton.makouski@gmail.com>
This commit is contained in:
Anton Makouski 2022-06-07 12:59:02 +03:00
parent ee3bfa0d20
commit a55062c6fd
2 changed files with 23 additions and 11 deletions

View file

@ -42,3 +42,15 @@ UNIT_TEST(ValidateAndFormat_building_levels)
TEST_EQUAL(tp.ValidateAndFormat_building_levels("2.51"), "2.5", ());
TEST_EQUAL(tp.ValidateAndFormat_building_levels("250"), "", ("Too many levels."));
}
UNIT_TEST(ValidateAndFormat_destination)
{
FeatureBuilderParams params;
MetadataTagProcessorImpl tp(params);
TEST_EQUAL(tp.ValidateAndFormat_destination("a1 a2"), "a1 a2", ());
TEST_EQUAL(tp.ValidateAndFormat_destination("b1-b2"), "b1-b2", ());
TEST_EQUAL(tp.ValidateAndFormat_destination(" c,d ;"), "c; d", ());
TEST_EQUAL(tp.ValidateAndFormat_destination("e,;f; g;"), "e; f; g", ());
TEST_EQUAL(tp.ValidateAndFormat_destination(""), "", ());
TEST_EQUAL(tp.ValidateAndFormat_destination("a1 a2;b1-b2; c,d ;e,;f; ;g"), "a1 a2; b1-b2; c; d; e; f; g", ());
}

View file

@ -148,18 +148,18 @@ string MetadataTagProcessorImpl::ValidateAndFormat_ele(string const & v) const
string MetadataTagProcessorImpl::ValidateAndFormat_destination(string const & v) const
{
// Normalization. "a1 a2;b1-b2; c,d ;e,;f; ;g" -> "a1 a2; b1-b2; c; d; e; f; g"
string r;
strings::Tokenize(v, ";,", [&](std::string_view d)
{
// Normalization. "a1 a2;b1-b2; c,d " " -> "a1 a2; b1-b2; c; d".
string r;
strings::Tokenize(v, ";,", [&](std::string_view d)
{
if (r.empty())
r = strings::Trim(d);
else
r += "; " + string(strings::Trim(d));
});
return r;
}
strings::Trim(d);
if (d.empty())
return;
if (!r.empty())
r += "; ";
r.append(d);
});
return r;
}
string MetadataTagProcessorImpl::ValidateAndFormat_destination_ref(string const & v) const