diff options
-rw-r--r-- | base/base_tests/string_utils_test.cpp | 6 | ||||
-rw-r--r-- | base/string_utils.cpp | 7 | ||||
-rw-r--r-- | base/string_utils.hpp | 3 | ||||
-rw-r--r-- | generator/booking_dataset.cpp | 6 |
4 files changed, 9 insertions, 13 deletions
diff --git a/base/base_tests/string_utils_test.cpp b/base/base_tests/string_utils_test.cpp index 84b48c1d85..9d416c287b 100644 --- a/base/base_tests/string_utils_test.cpp +++ b/base/base_tests/string_utils_test.cpp @@ -733,13 +733,13 @@ UNIT_TEST(NormalizeDigits_UniString) UNIT_TEST(CSV) { vector<string> target; - TEST(strings::ParseCSVRow(",Test\\,проверка,0,", target), ()); + strings::ParseCSVRow(",Test\\,проверка,0,", ',', target); vector<string> expected({"", "Test\\", "проверка", "0", ""}); TEST_EQUAL(target, expected, ()); - TEST(strings::ParseCSVRow("and there was none", target, ' ', 5), ()); + strings::ParseCSVRow("and there was none", ' ', target); vector<string> expected2({"and", "there", "", "was", "none"}); TEST_EQUAL(target, expected2, ()); - TEST(!strings::ParseCSVRow("", target), ()); + strings::ParseCSVRow("", 'q', target); vector<string> expected3; TEST_EQUAL(target, expected3, ()); } diff --git a/base/string_utils.cpp b/base/string_utils.cpp index 38c9c5ed33..6d017e2405 100644 --- a/base/string_utils.cpp +++ b/base/string_utils.cpp @@ -328,7 +328,7 @@ bool AlmostEqual(string const & str1, string const & str2, size_t mismatchedCoun return false; } -bool ParseCSVRow(string const & s, vector<string> & target, char const delimiter, size_t const columns) +void ParseCSVRow(string const & s, char const delimiter, vector<string> & target) { target.clear(); using It = TokenizeIterator<SimpleDelimiter, string::const_iterator, true>; @@ -341,12 +341,7 @@ bool ParseCSVRow(string const & s, vector<string> & target, char const delimiter // Special case: if the string is empty, return an empty array instead of {""}. if (target.size() == 1 && target[0].empty()) - { target.clear(); - return false; - } - - return columns <= 0 || target.size() == columns; } } // namespace strings diff --git a/base/string_utils.hpp b/base/string_utils.hpp index 6b9e1f89c5..561ec20fe1 100644 --- a/base/string_utils.hpp +++ b/base/string_utils.hpp @@ -308,8 +308,7 @@ void Tokenize(string const & str, char const * delims, TFunctor && f) /// Splits a string by the delimiter, keeps empty parts, on an empty string returns an empty vector. /// Does not support quoted columns, newlines in columns and escaped quotes. -/// @return false if the line is empty or number of columns differs from |columns|. -bool ParseCSVRow(string const & s, vector<string> & target, char const delimiter = ',', size_t const columns = 0); +void ParseCSVRow(string const & s, char const delimiter, vector<string> & target); /// @return code of last symbol in string or 0 if s is empty UniChar LastUniChar(string const & s); diff --git a/generator/booking_dataset.cpp b/generator/booking_dataset.cpp index 325beaee3c..b6328d10e2 100644 --- a/generator/booking_dataset.cpp +++ b/generator/booking_dataset.cpp @@ -31,7 +31,8 @@ bool CheckForValues(string const & value) BookingDataset::Hotel::Hotel(string const & src) { vector<string> rec; - CHECK(strings::ParseCSVRow(src, rec, '\t', FieldsCount()), ("Error parsing hotels.tsv line:", src)); + strings::ParseCSVRow(src, '\t', rec); + CHECK(rec.size() == FieldsCount(), ("Error parsing hotels.tsv line:", src)); strings::to_uint(rec[Index(Fields::Id)], id); strings::to_double(rec[Index(Fields::Latitude)], lat); @@ -174,7 +175,8 @@ void BookingDataset::BuildFeatures(function<void(OsmElement *)> const & fn) cons if (!hotel.translations.empty()) { vector<string> parts; - strings::ParseCSVRow(hotel.translations, parts, '|'); + strings::ParseCSVRow(hotel.translations, '|', parts); + CHECK(parts.size() % 3 == 0, ()); for (auto i = 0; i < parts.size(); i += 3) { e.AddTag("name:" + parts[i], parts[i + 1]); |