@@ -115,13 +115,19 @@ template <typename CharT, typename Iterator, typename EndIterator> constexpr CTR
115
115
return false ;
116
116
}
117
117
118
+ struct zero_terminated_string_end_iterator ;
118
119
template <auto ... String, size_t ... Idx, typename Iterator, typename EndIterator> constexpr CTRE_FORCE_INLINE string_match_result<Iterator> evaluate_match_string (Iterator current, [[maybe_unused]] const EndIterator end, std::index_sequence<Idx...>) noexcept {
119
- if constexpr (!std::is_same_v<Iterator, utf8_iterator> && is_random_accessible (typename std::iterator_traits<Iterator>::iterator_category{})) {
120
- bool same = (::std::distance (current, end) >= sizeof ...(String)) && ((String == *(current + Idx)) & ...);
120
+ #if __cpp_char8_t >= 201811
121
+ if constexpr (!std::is_same_v<Iterator, utf8_iterator> && is_random_accessible (typename std::iterator_traits<Iterator>::iterator_category{}) && !std::is_same_v<EndIterator, ctre::zero_terminated_string_end_iterator>) {
122
+ #else
123
+ if constexpr (is_random_accessible (typename std::iterator_traits<Iterator>::iterator_category{}) && !std::is_same_v<EndIterator, ctre::zero_terminated_string_end_iterator>) {
124
+ #endif
125
+ using char_type = decltype (*current);
126
+ bool same = ((size_t )std::distance (current, end) >= sizeof ...(String)) && ((static_cast <char_type>(String) == *(current + Idx)) && ...);
121
127
if (same) {
122
- return {current+= sizeof ...(String), same};
128
+ return { current += sizeof ...(String), same };
123
129
} else {
124
- return {current, same};
130
+ return { current, same };
125
131
}
126
132
} else {
127
133
bool same = (compare_character (String, current, end) && ... && true );
@@ -530,63 +536,63 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
530
536
}
531
537
532
538
template <typename T>
533
- constexpr bool is_string (T) {
539
+ constexpr bool is_string (T) noexcept {
534
540
return false ;
535
541
}
536
542
template <auto ... String>
537
- constexpr bool is_string (string<String...>) {
543
+ constexpr bool is_string (string<String...>)noexcept {
538
544
return true ;
539
545
}
540
546
541
547
template <typename T>
542
- constexpr bool is_string_like (T) {
548
+ constexpr bool is_string_like (T) noexcept {
543
549
return false ;
544
550
}
545
551
template <auto ... String>
546
- constexpr bool is_string_like (string<String...>) {
552
+ constexpr bool is_string_like (string<String...>) noexcept {
547
553
return true ;
548
554
}
549
555
template <typename CharacterLike, typename = std::enable_if_t <MatchesCharacter<CharacterLike>::template value<decltype (*std::declval<std::string_view::iterator>())>>>
550
- constexpr bool is_string_like (CharacterLike) {
556
+ constexpr bool is_string_like (CharacterLike) noexcept {
551
557
return true ;
552
558
}
553
559
554
560
template <typename ... Content>
555
- constexpr auto extract_leading_string (ctll::list<Content...>) -> ctll::list<Content...> {
561
+ constexpr auto extract_leading_string (ctll::list<Content...>) noexcept -> ctll::list<Content...> {
556
562
return {};
557
- };
563
+ }
558
564
template <typename ... Content>
559
- constexpr auto extract_leading_string (sequence<Content...>) -> sequence<Content...> {
565
+ constexpr auto extract_leading_string (sequence<Content...>) noexcept -> sequence<Content...> {
560
566
return {};
561
- };
567
+ }
562
568
563
569
// concatenation
564
570
template <auto C, auto ... String, typename ... Content>
565
- constexpr auto extract_leading_string (ctll::list<string<String...>, character<C>, Content...>) {
571
+ constexpr auto extract_leading_string (ctll::list<string<String...>, character<C>, Content...>) noexcept {
566
572
return extract_leading_string (ctll::list<string<String..., C>, Content...>());
567
573
}
568
574
569
575
template <auto ... StringA, auto ... StringB, typename ... Content>
570
- constexpr auto extract_leading_string (ctll::list<string<StringA...>, string<StringB...>, Content...>) {
571
- return extract_leading_string (ctll::list<string<StringA..., StringB>, Content...>());
576
+ constexpr auto extract_leading_string (ctll::list<string<StringA...>, string<StringB...>, Content...>) noexcept {
577
+ return extract_leading_string (ctll::list<string<StringA..., StringB... >, Content...>());
572
578
}
573
579
// move things up out of sequences
574
580
template <typename ... Content, typename ... Tail>
575
- constexpr auto extract_leading_string (ctll::list<sequence<Content...>, Tail...>) {
581
+ constexpr auto extract_leading_string (ctll::list<sequence<Content...>, Tail...>) noexcept {
576
582
return extract_leading_string (ctll::list<Content..., Tail...>());
577
583
}
578
584
579
585
template <typename T, typename ... Content, typename ... Tail>
580
- constexpr auto extract_leading_string (ctll::list<T, sequence<Content...>, Tail...>) {
586
+ constexpr auto extract_leading_string (ctll::list<T, sequence<Content...>, Tail...>) noexcept {
581
587
return extract_leading_string (ctll::list<T, Content..., Tail...>());
582
588
}
583
589
584
590
template <typename ... Content>
585
- constexpr auto make_into_sequence (ctll::list<Content...>) -> sequence<Content...> {
591
+ constexpr auto make_into_sequence (ctll::list<Content...>) noexcept -> sequence<Content...> {
586
592
return {};
587
593
}
588
594
template <typename ... Content>
589
- constexpr auto make_into_sequence (sequence<Content...>) -> sequence<Content...> {
595
+ constexpr auto make_into_sequence (sequence<Content...>) noexcept -> sequence<Content...> {
590
596
return {};
591
597
}
592
598
@@ -642,8 +648,12 @@ template <typename Iterator> struct string_search_result {
642
648
};
643
649
644
650
template <typename Iterator, typename EndIterator, auto ... String>
645
- constexpr CTRE_FORCE_INLINE string_search_result<Iterator> search_for_string (Iterator current, const EndIterator end, string<String...>) {
651
+ constexpr CTRE_FORCE_INLINE string_search_result<Iterator> search_for_string (Iterator current, const EndIterator end, string<String...>) noexcept {
652
+ #if __cpp_char8_t >= 201811
646
653
if constexpr (sizeof ...(String) > 2 && !std::is_same_v<Iterator, utf8_iterator> && is_random_accessible (typename std::iterator_traits<Iterator>::iterator_category{})) {
654
+ #else
655
+ if constexpr (sizeof ...(String) > 2 && is_random_accessible (typename std::iterator_traits<Iterator>::iterator_category{})) {
656
+ #endif
647
657
constexpr std::array<typename ::std::iterator_traits<Iterator>::value_type, sizeof ...(String)> chars{ String... };
648
658
constexpr std::array<ptrdiff_t , sizeof ...(String)> delta_2 = make_delta_2<typename ::std::iterator_traits<Iterator>::value_type>(string<String...>());
649
659
@@ -666,7 +676,7 @@ constexpr CTRE_FORCE_INLINE string_search_result<Iterator> search_for_string(Ite
666
676
}
667
677
668
678
return { current + str_size, current + str_size, false };
669
- } else if (sizeof ...(String)) {
679
+ } else if constexpr (sizeof ...(String)) {
670
680
// fallback to plain string matching
671
681
constexpr std::array<typename ::std::iterator_traits<Iterator>::value_type, sizeof ...(String)> chars{ String... };
672
682
constexpr typename ::std::iterator_traits<Iterator>::value_type first_char = chars.data ()[0 ];
0 commit comments