2014-04-08 06:51:53 +00:00
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
2017-07-10 03:28:12 +00:00
|
|
|
#include <Parsers/TokenIterator.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
#include <map>
|
2017-02-02 22:08:19 +00:00
|
|
|
#include <memory>
|
2018-05-16 10:25:10 +00:00
|
|
|
#include <Common/SipHash.h>
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
struct StringRange
|
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
const char * first = nullptr;
|
|
|
|
const char * second = nullptr;
|
2017-07-10 03:28:12 +00:00
|
|
|
|
2018-05-16 10:25:10 +00:00
|
|
|
StringRange() = default;
|
|
|
|
StringRange(const StringRange & other) = default;
|
2017-07-10 03:28:12 +00:00
|
|
|
StringRange(const char * begin, const char * end) : first(begin), second(end) {}
|
2018-05-16 10:25:10 +00:00
|
|
|
explicit StringRange(TokenIterator token) : first(token->begin), second(token->end) {}
|
2017-07-12 19:20:57 +00:00
|
|
|
|
|
|
|
StringRange(TokenIterator token_begin, TokenIterator token_end)
|
|
|
|
{
|
|
|
|
/// Empty range.
|
|
|
|
if (token_begin == token_end)
|
|
|
|
{
|
|
|
|
first = token_begin->begin;
|
|
|
|
second = token_begin->begin;
|
2017-09-06 02:37:36 +00:00
|
|
|
return;
|
2017-07-12 19:20:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TokenIterator token_last = token_end;
|
|
|
|
--token_last;
|
|
|
|
|
|
|
|
first = token_begin->begin;
|
|
|
|
second = token_last->end;
|
|
|
|
}
|
2018-05-16 10:25:10 +00:00
|
|
|
|
|
|
|
bool operator==(const StringRange & rhs) const { return std::tie(first, second) == std::tie(rhs.first, rhs.second); }
|
2017-07-10 03:28:12 +00:00
|
|
|
};
|
|
|
|
|
2016-05-28 10:15:36 +00:00
|
|
|
using StringPtr = std::shared_ptr<String>;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
2016-11-23 19:58:33 +00:00
|
|
|
|
|
|
|
inline String toString(const StringRange & range)
|
|
|
|
{
|
2018-02-26 03:37:08 +00:00
|
|
|
return range.first ? String(range.first, range.second) : String();
|
2016-11-23 19:58:33 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 10:25:10 +00:00
|
|
|
struct StringRangeHash
|
|
|
|
{
|
|
|
|
UInt64 operator()(const StringRange & range) const
|
|
|
|
{
|
|
|
|
SipHash hash;
|
|
|
|
hash.update(range.first);
|
|
|
|
hash.update(range.second);
|
|
|
|
return hash.get64();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
}
|
2018-05-16 10:25:10 +00:00
|
|
|
|