@@ -115,13 +115,19 @@ template <typename CharT, typename Iterator, typename EndIterator> constexpr CTR
115115 return false ;
116116}
117117
118+ struct zero_terminated_string_end_iterator ;
118119template <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)) && ...);
121127 if (same) {
122- return {current+= sizeof ...(String), same};
128+ return { current += sizeof ...(String), same };
123129 } else {
124- return {current, same};
130+ return { current, same };
125131 }
126132 } else {
127133 bool same = (compare_character (String, current, end) && ... && true );
@@ -530,63 +536,63 @@ constexpr CTRE_FORCE_INLINE R evaluate(const Iterator begin, Iterator current, c
530536}
531537
532538template <typename T>
533- constexpr bool is_string (T) {
539+ constexpr bool is_string (T) noexcept {
534540 return false ;
535541}
536542template <auto ... String>
537- constexpr bool is_string (string<String...>) {
543+ constexpr bool is_string (string<String...>)noexcept {
538544 return true ;
539545}
540546
541547template <typename T>
542- constexpr bool is_string_like (T) {
548+ constexpr bool is_string_like (T) noexcept {
543549 return false ;
544550}
545551template <auto ... String>
546- constexpr bool is_string_like (string<String...>) {
552+ constexpr bool is_string_like (string<String...>) noexcept {
547553 return true ;
548554}
549555template <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 {
551557 return true ;
552558}
553559
554560template <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...> {
556562 return {};
557- };
563+ }
558564template <typename ... Content>
559- constexpr auto extract_leading_string (sequence<Content...>) -> sequence<Content...> {
565+ constexpr auto extract_leading_string (sequence<Content...>) noexcept -> sequence<Content...> {
560566 return {};
561- };
567+ }
562568
563569// concatenation
564570template <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 {
566572 return extract_leading_string (ctll::list<string<String..., C>, Content...>());
567573}
568574
569575template <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...>());
572578}
573579// move things up out of sequences
574580template <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 {
576582 return extract_leading_string (ctll::list<Content..., Tail...>());
577583}
578584
579585template <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 {
581587 return extract_leading_string (ctll::list<T, Content..., Tail...>());
582588}
583589
584590template <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...> {
586592 return {};
587593}
588594template <typename ... Content>
589- constexpr auto make_into_sequence (sequence<Content...>) -> sequence<Content...> {
595+ constexpr auto make_into_sequence (sequence<Content...>) noexcept -> sequence<Content...> {
590596 return {};
591597}
592598
@@ -642,8 +648,12 @@ template <typename Iterator> struct string_search_result {
642648};
643649
644650template <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
646653 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
647657 constexpr std::array<typename ::std::iterator_traits<Iterator>::value_type, sizeof ...(String)> chars{ String... };
648658 constexpr std::array<ptrdiff_t , sizeof ...(String)> delta_2 = make_delta_2<typename ::std::iterator_traits<Iterator>::value_type>(string<String...>());
649659
@@ -666,7 +676,7 @@ constexpr CTRE_FORCE_INLINE string_search_result<Iterator> search_for_string(Ite
666676 }
667677
668678 return { current + str_size, current + str_size, false };
669- } else if (sizeof ...(String)) {
679+ } else if constexpr (sizeof ...(String)) {
670680 // fallback to plain string matching
671681 constexpr std::array<typename ::std::iterator_traits<Iterator>::value_type, sizeof ...(String)> chars{ String... };
672682 constexpr typename ::std::iterator_traits<Iterator>::value_type first_char = chars.data ()[0 ];
0 commit comments