diff --git a/src/Common/TLDListsHolder.cpp b/src/Common/TLDListsHolder.cpp index f0702f37e93..34bef8248b5 100644 --- a/src/Common/TLDListsHolder.cpp +++ b/src/Common/TLDListsHolder.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -11,11 +12,10 @@ namespace DB namespace ErrorCodes { extern const int TLD_LIST_NOT_FOUND; + extern const int LOGICAL_ERROR; } -/// /// TLDList -/// TLDList::TLDList(size_t size) : tld_container(size) , pool(std::make_unique(10 << 20)) @@ -31,9 +31,7 @@ bool TLDList::has(const StringRef & host) const return tld_container.has(host); } -/// /// TLDListsHolder -/// TLDListsHolder & TLDListsHolder::getInstance() { static TLDListsHolder instance; @@ -62,24 +60,22 @@ size_t TLDListsHolder::parseAndAddTldList(const std::string & name, const std::s std::unordered_set tld_list_tmp; ReadBufferFromFile in(path); + String line; while (!in.eof()) { - char * newline = find_first_symbols<'\n'>(in.position(), in.buffer().end()); - if (newline >= in.buffer().end()) - break; - - std::string_view line(in.position(), newline - in.position()); - in.position() = newline + 1; - + readEscapedStringUntilEOL(line, in); + ++in.position(); /// Skip comments if (line.size() > 2 && line[0] == '/' && line[1] == '/') continue; - trim(line); + line = trim(line, [](char c) { return std::isspace(c); }); /// Skip empty line if (line.empty()) continue; tld_list_tmp.emplace(line); } + if (!in.eof()) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Not all list had been read", name); TLDList tld_list(tld_list_tmp.size()); for (const auto & host : tld_list_tmp)