1#ifndef OSMIUM_UTIL_STRING_MATCHER_HPP
2#define OSMIUM_UTIL_STRING_MATCHER_HPP
45# if __has_include(<variant>)
47# ifdef __cpp_lib_variant
48# define OSMIUM_USE_STD_VARIANT
53#ifndef OSMIUM_USE_STD_VARIANT
54# include <boost/variant.hpp>
64#if defined(__GLIBCXX__)
65# if ((__cplusplus >= 201402L) || \
66 defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \
67 defined(_GLIBCXX_REGEX_STATE_LIMIT))
68# define OSMIUM_WITH_REGEX
70# pragma message("Disabling regex functionality. See source code for info.")
72#elif defined(__clang__)
73# if ((__clang_major__ > 3) || \
74 (__clang_minor__ == 3 && __clang_minor__ > 5))
75# define OSMIUM_WITH_REGEX
77# pragma message("Disabling regex functionality")
101 static bool match(
const char* )
noexcept {
105 template <
typename TChar,
typename TTraits>
106 void print(std::basic_ostream<TChar, TTraits>& out)
const {
107 out <<
"always_false";
119 static bool match(
const char* )
noexcept {
123 template <
typename TChar,
typename TTraits>
124 void print(std::basic_ostream<TChar, TTraits>& out)
const {
125 out <<
"always_true";
147 bool match(
const char* test_string)
const noexcept {
148 return !std::strcmp(
m_str.c_str(), test_string);
151 template <
typename TChar,
typename TTraits>
152 void print(std::basic_ostream<TChar, TTraits>& out)
const {
153 out <<
"equal[" <<
m_str <<
']';
175 bool match(
const char* test_string)
const noexcept {
176 return m_str.compare(0, std::string::npos, test_string, 0,
m_str.size()) == 0;
179 template <
typename TChar,
typename TTraits>
180 void print(std::basic_ostream<TChar, TTraits>& out)
const {
181 out <<
"prefix[" <<
m_str <<
']';
203 bool match(
const char* test_string)
const noexcept {
204 return std::strstr(test_string,
m_str.c_str()) !=
nullptr;
207 template <
typename TChar,
typename TTraits>
208 void print(std::basic_ostream<TChar, TTraits>& out)
const {
209 out <<
"substring[" <<
m_str <<
']';
214#ifdef OSMIUM_WITH_REGEX
218 class regex :
public matcher {
224 explicit regex(std::regex regex) :
225 m_regex(
std::move(regex)) {
228 bool match(
const char* test_string)
const noexcept {
229 return std::regex_search(test_string, m_regex);
232 template <
typename TChar,
typename TTraits>
233 void print(std::basic_ostream<TChar, TTraits>& out)
const {
251 explicit list(std::vector<std::string> strings) :
265 bool match(
const char* test_string)
const noexcept {
267 [&test_string](
const std::string& s){
268 return s == test_string;
272 template <
typename TChar,
typename TTraits>
273 void print(std::basic_ostream<TChar, TTraits>& out)
const {
276 out <<
'[' << s <<
']';
286#ifdef OSMIUM_USE_STD_VARIANT
296#ifdef OSMIUM_WITH_REGEX
304#ifndef OSMIUM_USE_STD_VARIANT
305 :
public boost::static_visitor<bool>
317 template <
typename TMatcher>
319 return t.match(
m_str);
324 template <
typename TChar,
typename TTraits>
326#ifndef OSMIUM_USE_STD_VARIANT
327 :
public boost::static_visitor<void>
331 std::basic_ostream<TChar, TTraits>*
m_out;
339 template <
typename TMatcher>
391#ifdef OSMIUM_WITH_REGEX
422 template <
typename TMatcher,
typename X =
typename std::enable_if<
423 std::is_base_of<matcher, TMatcher>::value,
void>
::type>
432#ifdef OSMIUM_USE_STD_VARIANT
446 template <
typename TChar,
typename TTraits>
447 void print(std::basic_ostream<TChar, TTraits>& out)
const {
448#ifdef OSMIUM_USE_STD_VARIANT
457 template <
typename TChar,
typename TTraits>
458 inline std::basic_ostream<TChar, TTraits>&
operator<<(std::basic_ostream<TChar, TTraits>& out,
const StringMatcher& matcher) {
465#undef OSMIUM_USE_STD_VARIANT
Definition: string_matcher.hpp:97
static bool match(const char *) noexcept
Definition: string_matcher.hpp:101
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:106
Definition: string_matcher.hpp:115
static bool match(const char *) noexcept
Definition: string_matcher.hpp:119
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:124
Definition: string_matcher.hpp:133
equal(const char *str)
Definition: string_matcher.hpp:143
std::string m_str
Definition: string_matcher.hpp:135
bool match(const char *test_string) const noexcept
Definition: string_matcher.hpp:147
equal(std::string str)
Definition: string_matcher.hpp:139
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:152
Definition: string_matcher.hpp:243
bool match(const char *test_string) const noexcept
Definition: string_matcher.hpp:265
list & add_string(const std::string &str)
Definition: string_matcher.hpp:260
list & add_string(const char *str)
Definition: string_matcher.hpp:255
std::vector< std::string > m_strings
Definition: string_matcher.hpp:245
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:273
list(std::vector< std::string > strings)
Definition: string_matcher.hpp:251
Definition: string_matcher.hpp:307
match_visitor(const char *str) noexcept
Definition: string_matcher.hpp:313
const char * m_str
Definition: string_matcher.hpp:309
bool operator()(const TMatcher &t) const noexcept
Definition: string_matcher.hpp:318
Definition: string_matcher.hpp:91
Definition: string_matcher.hpp:161
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:180
bool match(const char *test_string) const noexcept
Definition: string_matcher.hpp:175
prefix(std::string str)
Definition: string_matcher.hpp:167
std::string m_str
Definition: string_matcher.hpp:163
prefix(const char *str)
Definition: string_matcher.hpp:171
Definition: string_matcher.hpp:329
print_visitor(std::basic_ostream< TChar, TTraits > &out)
Definition: string_matcher.hpp:335
std::basic_ostream< TChar, TTraits > * m_out
Definition: string_matcher.hpp:331
void operator()(const TMatcher &t) const noexcept
Definition: string_matcher.hpp:340
Definition: string_matcher.hpp:189
std::string m_str
Definition: string_matcher.hpp:191
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:208
bool match(const char *test_string) const noexcept
Definition: string_matcher.hpp:203
substring(std::string str)
Definition: string_matcher.hpp:195
substring(const char *str)
Definition: string_matcher.hpp:199
Definition: string_matcher.hpp:86
StringMatcher()
Definition: string_matcher.hpp:351
StringMatcher(const std::vector< std::string > &strings)
Definition: string_matcher.hpp:410
StringMatcher(const char *str)
Definition: string_matcher.hpp:377
bool operator()(const char *str) const noexcept
Definition: string_matcher.hpp:431
boost::variant< always_false, always_true, equal, prefix, substring, list > matcher_type
Definition: string_matcher.hpp:299
void print(std::basic_ostream< TChar, TTraits > &out) const
Definition: string_matcher.hpp:447
bool operator()(const std::string &str) const noexcept
Definition: string_matcher.hpp:442
matcher_type m_matcher
Definition: string_matcher.hpp:301
StringMatcher(TMatcher &&matcher)
Definition: string_matcher.hpp:424
StringMatcher(bool result)
Definition: string_matcher.hpp:364
StringMatcher(const std::string &str)
Definition: string_matcher.hpp:387
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition: item_type.hpp:187
Definition: location.hpp:555