Fixed error; added a test

This commit is contained in:
Alexey Milovidov 2020-03-21 05:52:37 +03:00
parent e4192a0937
commit fea3ceca05
3 changed files with 16 additions and 3 deletions

View File

@ -306,7 +306,7 @@ inline void splitInto(To & to, const std::string & what, bool token_compress = f
{
const char * delimiter_or_end = find_first_symbols<symbols...>(pos, end);
if (!token_compress || pos + 1 < delimiter_or_end)
if (!token_compress || pos < delimiter_or_end)
to.emplace_back(pos, delimiter_or_end);
if (delimiter_or_end < end)

View File

@ -1,4 +1,5 @@
#include <string>
#include <vector>
#include <common/find_symbols.h>
#include <gtest/gtest.h>
@ -22,4 +23,16 @@ TEST(FindSymbols, SimpleTest)
ASSERT_EQ(find_last_symbols_or_null<' '>(begin, end), end - 11);
ASSERT_EQ(find_last_symbols_or_null<'H'>(begin, end), begin);
ASSERT_EQ((find_last_symbols_or_null<'a', 'e'>(begin, end)), end - 4);
{
std::vector<std::string> vals;
splitInto<' ', ','>(vals, "hello, world", true);
ASSERT_EQ(vals, (std::vector<std::string>{"hello", "world"}));
}
{
std::vector<std::string> vals;
splitInto<' ', ','>(vals, "s String", true);
ASSERT_EQ(vals, (std::vector<std::string>{"s", "String"}));
}
}

View File

@ -65,8 +65,8 @@ void BaseExternalTable::parseStructureFromStructureField(const std::string & arg
std::vector<std::string> vals;
splitInto<' ', ','>(vals, argument, true);
if (vals.size() & 1)
throw Exception("Odd number of attributes in section structure", ErrorCodes::BAD_ARGUMENTS);
if (vals.size() % 2 != 0)
throw Exception("Odd number of attributes in section structure: " + std::to_string(vals.size()), ErrorCodes::BAD_ARGUMENTS);
for (size_t i = 0; i < vals.size(); i += 2)
structure.emplace_back(vals[i], vals[i + 1]);