Skip to content

Commit fde29df

Browse files
author
Hana Dusíková
committed
add str() and view() ... also add missing update in single-header
1 parent 28bb5aa commit fde29df

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

include/ctre/return_type.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ template <size_t Id, typename Name = void> struct captured_content {
6767
return std::basic_string<char_type>(begin(), end());
6868
}
6969

70+
constexpr CTRE_FORCE_INLINE auto view() const noexcept {
71+
return std::basic_string_view<char_type>(&*_begin, static_cast<size_t>(std::distance(_begin, _end)));
72+
}
73+
74+
constexpr CTRE_FORCE_INLINE auto str() const noexcept {
75+
return std::basic_string<char_type>(begin(), end());
76+
}
77+
7078
constexpr CTRE_FORCE_INLINE operator std::basic_string_view<char_type>() const noexcept {
7179
return to_view();
7280
}
@@ -247,6 +255,14 @@ template <typename Iterator, typename... Captures> class regex_results {
247255
return _captures.template select<0>().to_string();
248256
}
249257

258+
constexpr CTRE_FORCE_INLINE auto view() const noexcept {
259+
return _captures.template select<0>().view();
260+
}
261+
262+
constexpr CTRE_FORCE_INLINE auto str() const noexcept {
263+
return _captures.template select<0>().to_string();
264+
}
265+
250266
constexpr CTRE_FORCE_INLINE regex_results & set_start_mark(Iterator pos) noexcept {
251267
_captures.template select<0>().set_start(pos);
252268
return *this;

single-header/ctre.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,9 +1057,8 @@ struct pcre {
10571057
static constexpr auto rule(c, ctll::term<'\\'>) -> ctll::push<ctll::anything, e, set_start, set2b, set_make, ctll::term<']'>>;
10581058
static constexpr auto rule(c, ctll::set<'!','$','\x28','\x29','*','+',',','.',':','<','=','>','?','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','0','s','t','u','v','w','x','y','z','\x7B','\x7D','1','2','3','4','5','6','7','8','9'>) -> ctll::push<ctll::anything, push_character, range, set_start, set2b, set_make, ctll::term<']'>>;
10591059
static constexpr auto rule(c, _others) -> ctll::push<ctll::anything, push_character, range, set_start, set2b, set_make, ctll::term<']'>>;
1060-
static constexpr auto rule(c, ctll::term<'-'>) -> ctll::push<ctll::anything, push_character, set_start, set2b, set_make, ctll::term<']'>>;
10611060
static constexpr auto rule(c, ctll::term<'^'>) -> ctll::push<ctll::anything, set2a, set_make_negative, ctll::term<']'>>;
1062-
static constexpr auto rule(c, ctll::set<']','|'>) -> ctll::reject;
1061+
static constexpr auto rule(c, ctll::set<'-',']','|'>) -> ctll::reject;
10631062

10641063
static constexpr auto rule(class_named_name, ctll::term<'x'>) -> ctll::push<ctll::anything, ctll::term<'d'>, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_xdigit>;
10651064
static constexpr auto rule(class_named_name, ctll::term<'d'>) -> ctll::push<ctll::anything, ctll::term<'i'>, ctll::term<'g'>, ctll::term<'i'>, ctll::term<'t'>, class_named_digit>;
@@ -2264,6 +2263,14 @@ template <size_t Id, typename Name = void> struct captured_content {
22642263
return std::basic_string<char_type>(begin(), end());
22652264
}
22662265

2266+
constexpr CTRE_FORCE_INLINE auto view() const noexcept {
2267+
return std::basic_string_view<char_type>(&*_begin, static_cast<size_t>(std::distance(_begin, _end)));
2268+
}
2269+
2270+
constexpr CTRE_FORCE_INLINE auto str() const noexcept {
2271+
return std::basic_string<char_type>(begin(), end());
2272+
}
2273+
22672274
constexpr CTRE_FORCE_INLINE operator std::basic_string_view<char_type>() const noexcept {
22682275
return to_view();
22692276
}
@@ -2444,6 +2451,14 @@ template <typename Iterator, typename... Captures> class regex_results {
24442451
return _captures.template select<0>().to_string();
24452452
}
24462453

2454+
constexpr CTRE_FORCE_INLINE auto view() const noexcept {
2455+
return _captures.template select<0>().view();
2456+
}
2457+
2458+
constexpr CTRE_FORCE_INLINE auto str() const noexcept {
2459+
return _captures.template select<0>().to_string();
2460+
}
2461+
24472462
constexpr CTRE_FORCE_INLINE regex_results & set_start_mark(Iterator pos) noexcept {
24482463
_captures.template select<0>().set_start(pos);
24492464
return *this;

0 commit comments

Comments
 (0)