Permalink
Browse files

matching/searching

  • Loading branch information...
Hana Dusíková
Hana Dusíková committed Sep 20, 2018
1 parent 482b6b2 commit fb2845b7669d7b20f7e0460e931a5bc3be5cc236
Showing with 40 additions and 70 deletions.
  1. +1 −0 NOTES.md
  2. +1 −1 include/ctre/evaluation.hpp
  3. +23 −1 include/ctre/functions.hpp
  4. +2 −14 include/ctre/literals.hpp
  5. +11 −52 include/ctre/wrapper.hpp
  6. +2 −2 tests/matching2.cpp
View
@@ -22,3 +22,4 @@
# Other unsupported "things"
* `[[.hyphen.]]` named characters
* `[[=M=]]` whatever this is
@@ -16,7 +16,7 @@ constexpr inline auto match_re(const Iterator begin, const Iterator end, Pattern
}
template <typename Iterator, typename Pattern>
constexpr inline auto float_match_re(const Iterator begin, const Iterator end, Pattern pattern) noexcept {
constexpr inline auto search_re(const Iterator begin, const Iterator end, Pattern pattern) noexcept {
using return_type = decltype(regex_results(std::declval<Iterator>(), find_captures(pattern)));
for (auto it{begin}; it != end; ++it) {
if (auto out = evaluate(begin, it, end, return_type{}, ctll::list<start_mark, Pattern, end_mark, accept>())) {
View
@@ -24,7 +24,18 @@ template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORC
#if __has_cpp_attribute(__cpp_nontype_template_parameter_class)
template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto fixed_match(std::string_view sv) noexcept {
template <basic_fixed_string input, typename ForwardIt> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto match(ForwardIt first, ForwardIt last) noexcept {
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
using re = decltype(front(typename tmp::output_type::stack_type()));
return ctre::float_regular_expression(re()).match(first, last);
}
#endif
#if __has_cpp_attribute(__cpp_nontype_template_parameter_class)
template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
@@ -33,6 +44,17 @@ template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORC
}
#endif
#if __has_cpp_attribute(__cpp_nontype_template_parameter_class)
template <basic_fixed_string input, typename ForwardIt> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto search(ForwardIt first, ForwardIt last) noexcept {
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
using re = decltype(front(typename tmp::output_type::stack_type()));
return ctre::regular_expression(re()).match(first, last);
}
#endif
}
#endif
View
@@ -44,24 +44,12 @@ template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORC
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
using re = decltype(front(typename tmp::output_type::stack_type()));
return ctre::float_regular_expression(re());
return ctre::regular_expression(re());
}
// duplicate for _ctre
#if !__has_cpp_attribute(__cpp_nontype_template_parameter_class)
template <typename CharT, CharT... charpack> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto operator""_fixed_ctre() noexcept {
constexpr auto & input = _fixed_string_reference<CharT, charpack...>;
#else
template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORCE_INLINE auto operator""_fixed_ctre() noexcept {
#endif
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
using re = decltype(front(typename tmp::output_type::stack_type()));
return ctre::regular_expression(re());
}
// add this when we will have concepts
// requires ctll::parser<ctre::pcre, _fixed_string_reference<CharT, charpack...>, ctre::pcre_actions>::template correct_with<pcre_context<>>
@@ -74,7 +62,7 @@ template <basic_fixed_string input> __attribute__((flatten)) constexpr CTRE_FORC
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
static_assert(tmp(), "Regular Expression contains syntax error.");
using re = decltype(front(typename tmp::output_type::stack_type()));
return ctre::float_regular_expression(re());
return ctre::regular_expression(re());
}
View
@@ -9,22 +9,6 @@ namespace ctre {
template <typename RE> struct regular_expression {
constexpr CTRE_FORCE_INLINE regular_expression(RE) noexcept { };
template <typename Iterator> constexpr CTRE_FORCE_INLINE auto operator()(Iterator begin, Iterator end) noexcept {
return match(begin, end);
}
constexpr CTRE_FORCE_INLINE auto operator()(std::string_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::wstring_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::u16string_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::u32string_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto match(Iterator begin, Iterator end) noexcept {
return match_re(begin, end, RE());
}
@@ -40,50 +24,25 @@ template <typename RE> struct regular_expression {
static constexpr CTRE_FORCE_INLINE auto match(std::u32string_view sv) noexcept {
return match(sv.begin(), sv.end());
}
};
template <typename RE> regular_expression(RE) -> regular_expression<RE>;
template <typename RE> struct float_regular_expression {
constexpr CTRE_FORCE_INLINE float_regular_expression(RE) noexcept { };
template <typename Iterator> constexpr CTRE_FORCE_INLINE auto operator()(Iterator begin, Iterator end) noexcept {
return match(begin, end);
template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto search(Iterator begin, Iterator end) noexcept {
return search_re(begin, end, RE());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::string_view sv) const noexcept {
return match(sv.begin(), sv.end());
static constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
return search(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::wstring_view sv) const noexcept {
return match(sv.begin(), sv.end());
static constexpr CTRE_FORCE_INLINE auto search(std::wstring_view sv) noexcept {
return search(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::u16string_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
constexpr CTRE_FORCE_INLINE auto operator()(std::u32string_view sv) const noexcept {
return match(sv.begin(), sv.end());
}
template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto match(Iterator begin, Iterator end) noexcept {
return float_match_re(begin, end, RE());
}
static constexpr CTRE_FORCE_INLINE auto match(std::string_view sv) noexcept {
return match(sv.begin(), sv.end());
}
static constexpr CTRE_FORCE_INLINE auto match(std::wstring_view sv) noexcept {
return match(sv.begin(), sv.end());
static constexpr CTRE_FORCE_INLINE auto search(std::u16string_view sv) noexcept {
return search(sv.begin(), sv.end());
}
static constexpr CTRE_FORCE_INLINE auto match(std::u16string_view sv) noexcept {
return match(sv.begin(), sv.end());
static constexpr CTRE_FORCE_INLINE auto search(std::u32string_view sv) noexcept {
return search(sv.begin(), sv.end());
}
static constexpr CTRE_FORCE_INLINE auto match(std::u32string_view sv) noexcept {
return match(sv.begin(), sv.end());
}
};
template <typename RE> float_regular_expression(RE) -> float_regular_expression<RE>;
template <typename RE> regular_expression(RE) -> regular_expression<RE>;
}
View
@@ -10,7 +10,7 @@ static_assert("abc"_pcre.match("abc"sv));
static_assert("a"_pcre.match("a"sv));
static_assert("a"_pcre.match("abc"sv));
static_assert("b"_pcre.match("abc"sv));
static_assert("b"_pcre.search("abc"sv));
static_assert(!"^b"_pcre.match("abc"sv));
static_assert(!"b"_pcre.match("a"sv));
static_assert("."_pcre.match("a"sv));
@@ -38,7 +38,7 @@ static_assert(!"(?:a|b|c)"_pcre.match("d"sv));
static_assert("(?:xy)?"_pcre.match("xy"sv));
static_assert("(?:xy)?"_pcre.match(""sv));
static_assert("(?:xy)?"_pcre.match("zxy"sv));
static_assert("(?:xy)?$"_pcre.match("zxy"sv));
static_assert("(?:xy)?$"_pcre.search("zxy"sv));
static_assert(!"~(?:xy)?$"_pcre.match("zxy"sv));
static_assert("^abc"_pcre.match("abc"sv));

0 comments on commit fb2845b

Please sign in to comment.