@@ -3229,6 +3229,12 @@ constexpr inline auto match_re(const Iterator begin, const EndIterator end, Patt
32293229 return evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, assert_end, end_mark, accept>());
32303230}
32313231
3232+ template <typename Iterator, typename EndIterator, typename Pattern>
3233+ constexpr inline auto starts_with_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
3234+ using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
3235+ return evaluate (begin, begin, end, return_type{}, ctll::list<start_mark, Pattern, end_mark, accept>());
3236+ }
3237+
32323238template <typename Iterator, typename EndIterator, typename Pattern>
32333239constexpr inline auto search_re (const Iterator begin, const EndIterator end, Pattern pattern) noexcept {
32343240 using return_type = decltype (regex_results (std::declval<Iterator>(), find_captures (pattern)));
@@ -3687,6 +3693,9 @@ template <typename RE> struct regular_expression {
36873693 template <typename IteratorBegin, typename IteratorEnd> constexpr CTRE_FORCE_INLINE static auto search_2 (IteratorBegin begin, IteratorEnd end) noexcept {
36883694 return search_re (begin, end, RE ());
36893695 }
3696+ template <typename IteratorBegin, typename IteratorEnd> constexpr CTRE_FORCE_INLINE static auto starts_with_2 (IteratorBegin begin, IteratorEnd end) noexcept {
3697+ return starts_with (begin, end, RE ());
3698+ }
36903699 constexpr CTRE_FORCE_INLINE regular_expression () noexcept { }
36913700 constexpr CTRE_FORCE_INLINE regular_expression (RE) noexcept { }
36923701 template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto match (Iterator begin, Iterator end) noexcept {
@@ -3719,6 +3728,7 @@ template <typename RE> struct regular_expression {
37193728 template <typename Range, typename = typename std::enable_if<RangeLikeType<Range>::value>::type> static constexpr CTRE_FORCE_INLINE auto match (Range && range) noexcept {
37203729 return match (std::begin (range), std::end (range));
37213730 }
3731+
37223732 template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto search (Iterator begin, Iterator end) noexcept {
37233733 return search_re (begin, end, RE ());
37243734 }
@@ -3749,6 +3759,37 @@ template <typename RE> struct regular_expression {
37493759 template <typename Range> static constexpr CTRE_FORCE_INLINE auto search (Range && range) noexcept {
37503760 return search (std::begin (range), std::end (range));
37513761 }
3762+
3763+ template <typename Iterator> constexpr CTRE_FORCE_INLINE static auto starts_with (Iterator begin, Iterator end) noexcept {
3764+ return starts_with_re (begin, end, RE ());
3765+ }
3766+ constexpr CTRE_FORCE_INLINE static auto starts_with (const char * s) noexcept {
3767+ return starts_with_2 (s, zero_terminated_string_end_iterator ());
3768+ }
3769+ static constexpr CTRE_FORCE_INLINE auto starts_with (const wchar_t * s) noexcept {
3770+ return starts_with_2 (s, zero_terminated_string_end_iterator ());
3771+ }
3772+ static constexpr CTRE_FORCE_INLINE auto starts_with (const std::string & s) noexcept {
3773+ return starts_with_2 (s.c_str (), zero_terminated_string_end_iterator ());
3774+ }
3775+ static constexpr CTRE_FORCE_INLINE auto starts_with (const std::wstring & s) noexcept {
3776+ return starts_with_2 (s.c_str (), zero_terminated_string_end_iterator ());
3777+ }
3778+ static constexpr CTRE_FORCE_INLINE auto starts_with (std::string_view sv) noexcept {
3779+ return starts_with (sv.begin (), sv.end ());
3780+ }
3781+ static constexpr CTRE_FORCE_INLINE auto starts_with (std::wstring_view sv) noexcept {
3782+ return starts_with (sv.begin (), sv.end ());
3783+ }
3784+ static constexpr CTRE_FORCE_INLINE auto starts_with (std::u16string_view sv) noexcept {
3785+ return starts_with (sv.begin (), sv.end ());
3786+ }
3787+ static constexpr CTRE_FORCE_INLINE auto starts_with (std::u32string_view sv) noexcept {
3788+ return starts_with (sv.begin (), sv.end ());
3789+ }
3790+ template <typename Range> static constexpr CTRE_FORCE_INLINE auto starts_with (Range && range) noexcept {
3791+ return starts_with (std::begin (range), std::end (range));
3792+ }
37523793};
37533794
37543795template <typename RE> regular_expression (RE) -> regular_expression<RE>;
@@ -3930,6 +3971,16 @@ template <typename RE> struct regex_search_t {
39303971 }
39313972};
39323973
3974+ template <typename RE> struct regex_starts_with_t {
3975+ template <typename ... Args> CTRE_FORCE_INLINE constexpr auto operator ()(Args && ... args) const noexcept {
3976+ auto re_obj = ctre::regular_expression<RE>();
3977+ return re_obj.starts_with (std::forward<Args>(args)...);
3978+ }
3979+ template <typename ... Args> CTRE_FORCE_INLINE constexpr auto try_extract (Args && ... args) const noexcept {
3980+ return operator ()(std::forward<Args>(args)...);
3981+ }
3982+ };
3983+
39333984#if (__cpp_nontype_template_parameter_class || (__cpp_nontype_template_args >= 201911L))
39343985
39353986template <auto input> struct regex_builder {
@@ -3943,6 +3994,8 @@ template <ctll::fixed_string input> static constexpr inline auto match = regex_m
39433994
39443995template <ctll::fixed_string input> static constexpr inline auto search = regex_search_t <typename regex_builder<input>::type>();
39453996
3997+ template <ctll::fixed_string input> static constexpr inline auto starts_with = regex_starts_with_t <typename regex_builder<input>::type>();
3998+
39463999#else
39474000
39484001template <auto & input> struct regex_builder {
@@ -3955,6 +4008,8 @@ template <auto & input> static constexpr inline auto match = regex_match_t<typen
39554008
39564009template <auto & input> static constexpr inline auto search = regex_search_t <typename regex_builder<input>::type>();
39574010
4011+ template <auto & input> static constexpr inline auto starts_with = regex_starts_with_t <typename regex_builder<input>::type>();
4012+
39584013#endif
39594014
39604015}
0 commit comments