diff --git a/include/fmt/format.h b/include/fmt/format.h index 17be15b4..9d380000 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -50,6 +50,7 @@ #endif #if FMT_USE_TEXT # include +# include #endif #ifdef __clang__ @@ -922,7 +923,11 @@ inline size_t compute_width(basic_string_view s) { inline size_t compute_width(string_view s) { #if FMT_USE_TEXT basic_memory_buffer code_points; - for (auto cp : boost::text::make_to_utf32_range(s)) code_points.push_back(cp); + const char* s_end = s.data() + s.size(); + boost::text::utf_8_to_32_iterator begin(s.data(), s.data(), + s_end), + end(s.data(), s_end, s_end); + for (auto it = begin; it != end; ++it) code_points.push_back(*it); size_t width = 0; for (auto it = code_points.begin(), end = code_points.end(); it != end; it = boost::text::next_grapheme_break(it, end)) { diff --git a/src/text/boost/text/detail/lzw.hpp b/src/text/boost/text/detail/lzw.hpp index 2be67846..f82ad8da 100644 --- a/src/text/boost/text/detail/lzw.hpp +++ b/src/text/boost/text/detail/lzw.hpp @@ -1,6 +1,7 @@ #ifndef BOOST_TEXT_DETAIL_LZW_HPP #define BOOST_TEXT_DETAIL_LZW_HPP +#include #include #include diff --git a/src/text/boost/text/grapheme_break.hpp b/src/text/boost/text/grapheme_break.hpp index 22c93684..f1639f9c 100644 --- a/src/text/boost/text/grapheme_break.hpp +++ b/src/text/boost/text/grapheme_break.hpp @@ -2,7 +2,7 @@ #define BOOST_TEXT_GRAPHEME_BREAK_HPP #include -#include +#include #include #include @@ -157,8 +157,7 @@ constexpr std::array, 15> grapheme_breaks = {{ } template - auto next_grapheme_break(CPIter first, Sentinel last) noexcept - -> detail::cp_iter_ret_t + CPIter next_grapheme_break(CPIter first, Sentinel last) noexcept { if (first == last) return first; diff --git a/src/text/boost/text/utility.hpp b/src/text/boost/text/utility.hpp deleted file mode 100644 index 56e7c420..00000000 --- a/src/text/boost/text/utility.hpp +++ /dev/null @@ -1,248 +0,0 @@ -#ifndef BOOST_TEXT_UTILITY_HPP -#define BOOST_TEXT_UTILITY_HPP - -#include -#include -#include - - -namespace boost { namespace text { - - /** A range that adapts a sequence of `char const *` to a sequence of code - points. */ - struct utf32_range - { - using iterator = utf_8_to_32_iterator; - - utf32_range() : - first_(nullptr, nullptr, nullptr), - last_(nullptr, nullptr, nullptr) - {} - utf32_range(char const * f, char const * l) : - first_(f, f, l), - last_(f, l, l) - {} - utf32_range(iterator f, iterator l) : first_(f), last_(l) {} - template - utf32_range(CharRange const & r) : - first_(std::begin(r), std::begin(r), std::end(r)), - last_(std::begin(r), std::end(r), std::end(r)) - {} - - bool empty() const noexcept { return first_ == last_; } - - iterator begin() const noexcept { return first_; } - iterator end() const noexcept { return last_; } - - friend bool operator==(utf32_range lhs, utf32_range rhs) - { - return lhs.first_ == rhs.first_ && lhs.last_ == rhs.last_; - } - friend bool operator!=(utf32_range lhs, utf32_range rhs) - { - return !(lhs == rhs); - } - - private: - iterator first_; - iterator last_; - }; - - /** A range of code points. */ - template - struct cp_range - { - using iterator = CPIter; - using sentinel = Sentinel; - - static_assert( - detail::is_cp_iter::value, - "CPIter must be a code point iterator"); - - cp_range() {} - cp_range(iterator first, sentinel last) : first_(first), last_(last) {} - - bool empty() const noexcept { return first_ == last_; } - - iterator begin() const { return first_; } - sentinel end() const { return last_; } - - friend bool operator==(cp_range lhs, cp_range rhs) - { - return lhs.first_ == rhs.first_ && lhs.last_ == rhs.last_; - } - friend bool operator!=(cp_range lhs, cp_range rhs) - { - return !(lhs == rhs); - } - - private: - iterator first_; - sentinel last_; - }; - - /** A generic range. */ - template - struct range - { - using iterator = Iter; - using sentinel = Sentinel; - - range() {} - range(iterator first, sentinel last) : first_(first), last_(last) {} - - bool empty() const noexcept { return first_ == last_; } - - iterator begin() const { return first_; } - sentinel end() const { return last_; } - - friend bool operator==(range lhs, range rhs) - { - return lhs.first_ == rhs.first_ && lhs.last_ == rhs.last_; - } - friend bool operator!=(range lhs, range rhs) { return !(lhs == rhs); } - - private: - iterator first_; - sentinel last_; - }; - - namespace detail { - template - using remove_cv_ref_t = typename std::remove_cv< - typename std::remove_reference::type>::type; - - template - using iterator_t = - remove_cv_ref_t().begin())>; - - template - using sentinel_t = - remove_cv_ref_t().end())>; - - template< - template class IterTemplate, - typename Iter, - typename Sentinel> - struct make_range_impl_t - { - using iter_t = - IterTemplate; - static range - call(Iter first, Sentinel last) noexcept - { - return {iter_t{first, first, last}, last}; - } - }; - - template< - template class IterTemplate, - typename Iter> - struct make_range_impl_t - { - using iter_t = IterTemplate; - static range call(Iter first, Iter last) noexcept - { - return {iter_t{first, first, last}, iter_t{first, last, last}}; - } - }; - - template< - template class IterTemplate, - typename Range> - struct make_range_t - { - using impl_t = make_range_impl_t< - IterTemplate, - iterator_t, - sentinel_t>; - static auto call(Range const & r) noexcept - -> decltype(impl_t::call(std::begin(r), std::end(r))) - { - return impl_t::call(std::begin(r), std::end(r)); - } - }; - } - -#ifdef BOOST_TEXT_DOXYGEN - - /** Returns a range of code points transcoded from the given range of - UTF-8 code units. - - This function only participates in overload resolution if `CharRange` - models the CharRange concept. */ - template - detail::unspecified make_to_utf32_range(CharRange const & r) noexcept; - - /** Returns a range of UTF-8 code units transcoded from the given range of - code points. - - This function only participates in overload resolution if `CPRange` - models the CPRange concept. */ - template - detail::unspecified make_from_utf32_range(CPRange const & r) noexcept; - - /** Returns a range of UTF-16 code units transcoded from the given range - of UTF-8 code units. - - This function only participates in overload resolution if `CharRange` - models the CharRange concept. */ - template - detail::unspecified make_to_utf16_range(CharRange const & r) noexcept; - - /** Returns a range of UTF-8 code units transcoded from the given range of - UTF-16 code units. - - This function only participates in overload resolution if - `Char16Range` is a range of 16-bit integral values, each of which is - convertible to `uint16_t`. */ - template - detail::unspecified make_from_utf16_range(Char16Range const & r) noexcept; - -#else - - template - auto make_to_utf32_range(CharRange const & r) noexcept - -> detail::rng_alg_ret_t< - decltype( - detail::make_range_t::call(r)), - CharRange> - { - return detail::make_range_t::call(r); - } - - template - auto make_from_utf32_range(CPRange const & r) noexcept - -> detail::cp_rng_alg_ret_t< - decltype( - detail::make_range_t::call(r)), - CPRange> - { - return detail::make_range_t::call(r); - } - - template - auto make_to_utf16_range(CharRange const & r) noexcept - -> detail::rng_alg_ret_t< - decltype( - detail::make_range_t::call(r)), - CharRange> - { - return detail::make_range_t::call(r); - } - - template - auto make_from_utf16_range(Char16Range const & r) noexcept - -> detail::rng16_alg_ret_t< - decltype(detail::make_range_t:: - call(r)), - Char16Range> - { - return detail::make_range_t::call(r); - } - -#endif - -}} - -#endif