diff --git a/include/iris/x4/char/char_set.hpp b/include/iris/x4/char/char_set.hpp index 5756c534d..e29e18c50 100644 --- a/include/iris/x4/char/char_set.hpp +++ b/include/iris/x4/char/char_set.hpp @@ -11,12 +11,13 @@ ==============================================================================*/ #include -#include #include #include +#include #include +#include #include #include #include @@ -72,36 +73,29 @@ struct char_set : char_parser> static constexpr bool has_attribute = !std::is_same_v; - template - constexpr explicit char_set(R const& str) - noexcept(detail::cast_char_noexcept, char_type>) + constexpr explicit char_set(std::basic_string_view const str) + // never noexcept; requires vector insertion { - static_assert(detail::cast_char_viable, char_type>); - - using detail::cast_char; // ADL introduction - for (auto definition = std::ranges::begin(str); definition != std::ranges::end(str);) { auto const ch = *definition; auto next_definition = std::next(definition); if (next_definition == std::ranges::end(str)) { - chset.set(cast_char(ch)); + chset_.set(ch); break; } auto next_ch = *next_definition; - if (next_ch == '-') { + if (next_ch == detail::char_tokens::hyphen) { next_definition = std::next(next_definition); if (next_definition == std::ranges::end(str)) { - chset.set(cast_char(ch)); - chset.set('-'); + chset_.set(ch); + chset_.set(detail::char_tokens::hyphen); break; } - chset.set( - cast_char(ch), - cast_char(*next_definition) - ); + chset_.set(ch, *next_definition); + } else { - chset.set(cast_char(ch)); + chset_.set(ch); } definition = next_definition; @@ -111,17 +105,18 @@ struct char_set : char_parser> template [[nodiscard]] constexpr bool test(Char ch_, Context const& ctx) const noexcept { - static_assert(noexcept(x4::get_case_compare(ctx).in_set(ch_, chset))); - return x4::get_case_compare(ctx).in_set(ch_, chset); + static_assert(noexcept(x4::get_case_compare(ctx).in_set(ch_, chset_))); + return x4::get_case_compare(ctx).in_set(ch_, chset_); } - detail::basic_chset chset; - [[nodiscard]] std::string get_x4_info() const { // TODO: escape return "char-set"; // TODO: make more user-friendly } + +private: + detail::basic_chset chset_; }; } // iris::x4 diff --git a/include/iris/x4/core/char_traits.hpp b/include/iris/x4/core/char_traits.hpp index 793fff880..256b129e1 100644 --- a/include/iris/x4/core/char_traits.hpp +++ b/include/iris/x4/core/char_traits.hpp @@ -11,7 +11,7 @@ // This header is intended for inclusion by user-facing, non-parser headers. // Do not add includes specific to X4's parser implementation here. -#include +#include // IWYU pragma: keep #include #include @@ -58,6 +58,31 @@ concept CharIncompatibleWith = CharLike && !std::same_as; +namespace detail { + +template +struct char_tokens; + +template<> +struct char_tokens +{ + static constexpr char hyphen = '-'; +}; + +template<> +struct char_tokens +{ + static constexpr wchar_t hyphen = L'-'; +}; + +template<> +struct char_tokens +{ + static constexpr char32_t hyphen = U'-'; +}; + +} // detail + } // iris::x4 #endif