2017-03-10 17:52:36 +00:00
|
|
|
#pragma once
|
2018-08-30 18:40:46 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/OptimizedRegularExpression.h>
|
2018-08-30 18:40:46 +00:00
|
|
|
#include <Common/ObjectPool.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
2018-08-30 18:40:46 +00:00
|
|
|
#include <Functions/likePatternToRegexp.h>
|
2017-03-11 00:27:59 +00:00
|
|
|
|
2017-03-10 17:52:36 +00:00
|
|
|
|
|
|
|
namespace ProfileEvents
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const Event RegexpCreated;
|
2017-03-10 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 00:04:08 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2017-03-10 17:52:36 +00:00
|
|
|
|
|
|
|
namespace Regexps
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
using Regexp = OptimizedRegularExpressionImpl<false>;
|
|
|
|
using Pool = ObjectPoolMap<Regexp, String>;
|
|
|
|
|
|
|
|
template <bool like>
|
|
|
|
inline Regexp createRegexp(const std::string & pattern, int flags) { return {pattern, flags}; }
|
|
|
|
|
|
|
|
template <>
|
|
|
|
inline Regexp createRegexp<true>(const std::string & pattern, int flags) { return {likePatternToRegexp(pattern), flags}; }
|
|
|
|
|
|
|
|
template <bool like, bool no_capture>
|
|
|
|
inline Pool::Pointer get(const std::string & pattern)
|
|
|
|
{
|
|
|
|
/// C++11 has thread-safe function-local statics on most modern compilers.
|
2017-05-13 22:19:04 +00:00
|
|
|
static Pool known_regexps; /// Different variables for different pattern parameters.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
return known_regexps.get(pattern, [&pattern]
|
|
|
|
{
|
|
|
|
int flags = OptimizedRegularExpression::RE_DOT_NL;
|
|
|
|
if (no_capture)
|
|
|
|
flags |= OptimizedRegularExpression::RE_NO_CAPTURE;
|
|
|
|
|
|
|
|
ProfileEvents::increment(ProfileEvents::RegexpCreated);
|
|
|
|
return new Regexp{createRegexp<like>(pattern, flags)};
|
|
|
|
});
|
|
|
|
}
|
2017-03-10 17:52:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|