From 1e1aa58aafc40c52a0d4dd64611f7bdba19e5ff3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Aug 2022 19:06:49 +0100 Subject: Make utf8_string_view work on any contiguous collection of chars const char * const or container with .data() and .length() --- lib/unicode.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/unicode.h b/lib/unicode.h index 2945650..f69c43c 100644 --- a/lib/unicode.h +++ b/lib/unicode.h @@ -45,25 +45,30 @@ struct utf8_string_view { const char * pos; }; + template // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) - template constexpr utf8_string_view(Args &&... args) : str {std::forward(args)...} { } + constexpr utf8_string_view(const Str & str) : begin_ {str.data()}, end_ {str.data() + str.length()} + { + } + // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) + constexpr utf8_string_view(const char * const str) : utf8_string_view {std::string_view {str}} { } [[nodiscard]] auto begin() const { - return iter {str.cbegin()}; + return iter {begin_}; } [[nodiscard]] auto end() const { - return iter {str.cend()}; + return iter {end_}; } [[nodiscard]] size_t length() const; private: - std::string_view str; + const char *begin_, *end_; }; template<> struct std::iterator_traits { using difference_type = size_t; -- cgit v1.2.3