From 6b2b53b0f3113775d0f89684261560908c06c873 Mon Sep 17 00:00:00 2001 From: Edward Nolan Date: Sun, 13 Sep 2026 20:26:25 -0400 Subject: [PATCH] Fix italicization of exposition-only data members --- include/beman/utf_view/to_utf_view.hpp | 144 ++++++++++++------------- papers/P2728.md | 87 ++++++++------- papers/generator/post_clang_format.py | 5 +- 3 files changed, 122 insertions(+), 114 deletions(-) diff --git a/include/beman/utf_view/to_utf_view.hpp b/include/beman/utf_view/to_utf_view.hpp index d2692747..a6140946 100644 --- a/include/beman/utf_view/to_utf_view.hpp +++ b/include/beman/utf_view/to_utf_view.hpp @@ -283,21 +283,21 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego public: // MSVC has some bug with their implementation of friendship #endif /* !PAPER */ - [[no_unique_address]] std::conditional_t, std::ranges::iterator_t, std::monostate> begin_{}; -/* PAPER: iterator_t begin_{}; // @*exposition only*@, present only if */ + [[no_unique_address]] std::conditional_t, std::ranges::iterator_t, std::monostate> exposition_only_begin_{}; +/* PAPER: iterator_t @*begin_*@{}; // @*exposition only*@, present only if */ /* PAPER: // bidirectional_range is true */ /* PAPER */ - std::ranges::iterator_t current_{}; // @*exposition only*@ + std::ranges::iterator_t exposition_only_current_{}; // @*exposition only*@ /* !PAPER */ - [[no_unique_address]] std::ranges::sentinel_t end_{}; // @*exposition only*@ -/* PAPER: sentinel_t end_; // @*exposition only*@ */ + [[no_unique_address]] std::ranges::sentinel_t exposition_only_end_{}; // @*exposition only*@ +/* PAPER: sentinel_t @*end_*@; // @*exposition only*@ */ - detail::fake_inplace_vector buf_{}; // @*exposition only*@ -/* PAPER: inplace_vector buf_{}; // @*exposition only*@ */ + detail::fake_inplace_vector exposition_only_buf_{}; // @*exposition only*@ +/* PAPER: inplace_vector @*buf_*@{}; // @*exposition only*@ */ /* PAPER */ - std::int8_t buf_index_{}; // @*exposition only*@ - std::uint8_t to_increment_{}; // @*exposition only*@ + std::int8_t exposition_only_buf_index_{}; // @*exposition only*@ + std::uint8_t exposition_only_to_increment_{}; // @*exposition only*@ /* !PAPER */ std::expected success_{}; @@ -326,11 +326,11 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego std::ranges::iterator_t current, std::ranges::sentinel_t end) // @*exposition only*@ requires std::ranges::bidirectional_range - : begin_(std::move(begin)), - current_(std::move(current)), - end_(end) + : exposition_only_begin_(std::move(begin)), + exposition_only_current_(std::move(current)), + exposition_only_end_(end) { - if (current_ != exposition_only_end()) + if (exposition_only_current_ != exposition_only_end()) exposition_only_read(); } @@ -338,13 +338,13 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego std::ranges::iterator_t current, std::ranges::sentinel_t end) // @*exposition only*@ requires (!std::ranges::bidirectional_range) - : current_(std::move(current)), - end_(end) + : exposition_only_current_(std::move(current)), + exposition_only_end_(end) { - if (current_ != exposition_only_end()) + if (exposition_only_current_ != exposition_only_end()) exposition_only_read(); else if constexpr (!std::ranges::forward_range) { - buf_index_ = -1; + exposition_only_buf_index_ = -1; } } @@ -353,13 +353,13 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego constexpr const std::ranges::iterator_t& base() const& noexcept requires std::ranges::forward_range { - return current_; + return exposition_only_current_; } constexpr std::ranges::iterator_t base() && requires std::ranges::forward_range { - return std::move(current_); + return std::move(exposition_only_current_); } /* PAPER: constexpr value_type operator*() const; */ @@ -370,7 +370,7 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego return std::unexpected{success_.error()}; } } - return buf_[buf_index_]; + return exposition_only_buf_[exposition_only_buf_index_]; } /* PAPER */ @@ -378,7 +378,7 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego { if (!exposition_only_success()) { /* !PAPER */ - assert(buf_index_ == 0); + assert(exposition_only_buf_index_ == 0); /* PAPER */ if constexpr (std::is_same_v) { exposition_only_advance_one(); @@ -408,10 +408,10 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego constexpr exposition_only_iterator& operator--() requires std::ranges::bidirectional_range { - if (!buf_index_) + if (!exposition_only_buf_index_) exposition_only_read_reverse(); else - --buf_index_; + --exposition_only_buf_index_; return *this; } @@ -427,7 +427,7 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego const exposition_only_iterator& rhs) requires std::equality_comparable> { - return lhs.current_ == rhs.current_ && lhs.buf_index_ == rhs.buf_index_; + return lhs.exposition_only_current_ == rhs.exposition_only_current_ && lhs.exposition_only_buf_index_ == rhs.exposition_only_buf_index_; } private: @@ -458,12 +458,12 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego constexpr std::ranges::iterator_t begin() const requires std::ranges::bidirectional_range { - return begin_; + return exposition_only_begin_; } /* PAPER */ constexpr std::ranges::sentinel_t exposition_only_end() const { // @*exposition only*@ - return end_; + return exposition_only_end_; } /* PAPER: constexpr expected @*success*@() const noexcept requires(E == to_utf_view_kind::expected); // @*exposition only*@ */ @@ -479,19 +479,19 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego constexpr void exposition_only_advance_one() // @*exposition only*@ { - ++buf_index_; + ++exposition_only_buf_index_; /* !PAPER */ - if (buf_index_ == static_cast(buf_.size())) { + if (exposition_only_buf_index_ == static_cast(exposition_only_buf_.size())) { /* PAPER */ - /* PAPER: if (buf_index_ == buf_.size()) { */ + /* PAPER: if (exposition_only_buf_index_ == exposition_only_buf_.size()) { */ if constexpr (std::ranges::forward_range) { - buf_index_ = 0; - std::advance(current_, to_increment_); + exposition_only_buf_index_ = 0; + std::advance(exposition_only_current_, exposition_only_to_increment_); } - if (current_ != exposition_only_end()) { + if (exposition_only_current_ != exposition_only_end()) { exposition_only_read(); } else if constexpr (!std::ranges::forward_range) { - buf_index_ = -1; + exposition_only_buf_index_ = -1; } } } @@ -605,8 +605,8 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego } constexpr decode_code_point_result decode_code_point_utf8() { - guard> g{current_, current_}; - return decode_code_point_utf8_impl(current_, exposition_only_end()); + guard> g{exposition_only_current_, exposition_only_current_}; + return decode_code_point_utf8_impl(exposition_only_current_, exposition_only_end()); } static constexpr decode_code_point_result decode_code_point_utf16_impl( @@ -646,8 +646,8 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego } constexpr decode_code_point_result decode_code_point_utf16() { - guard> g{current_, current_}; - return decode_code_point_utf16_impl(current_, exposition_only_end()); + guard> g{exposition_only_current_, exposition_only_current_}; + return decode_code_point_utf16_impl(exposition_only_current_, exposition_only_end()); } static constexpr decode_code_point_result decode_code_point_utf32_impl( @@ -671,44 +671,44 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego } constexpr decode_code_point_result decode_code_point_utf32() { - guard> g{current_, current_}; - return decode_code_point_utf32_impl(current_); + guard> g{exposition_only_current_, exposition_only_current_}; + return decode_code_point_utf32_impl(exposition_only_current_); } // Encode the code point c as one or more code units in buf. constexpr void update(char32_t c, std::uint8_t to_incr) { - to_increment_ = to_incr; - buf_index_ = 0; - buf_.clear(); + exposition_only_to_increment_ = to_incr; + exposition_only_buf_index_ = 0; + exposition_only_buf_.clear(); if constexpr (std::is_same_v) { - buf_.push_back(c); + exposition_only_buf_.push_back(c); } else if constexpr (std::is_same_v) { if (c <= std::numeric_limits::max()) { - buf_.push_back(static_cast(c)); + exposition_only_buf_.push_back(static_cast(c)); } else { // From http://www.unicode.org/faq/utf_bom.html#utf16-4 const char32_t lead_offset = 0xD800 - (0x10000 >> 10); char16_t lead = lead_offset + (c >> 10); char16_t trail = 0xDC00 + (c & 0x3FF); - buf_.push_back(lead); - buf_.push_back(trail); + exposition_only_buf_.push_back(lead); + exposition_only_buf_.push_back(trail); } } else if constexpr (std::is_same_v) { int bits = std::bit_width(static_cast(c)); if (bits <= 7) [[likely]] { - buf_.push_back(static_cast(c)); + exposition_only_buf_.push_back(static_cast(c)); } else if (bits <= 11) { - buf_.push_back(0xC0 | (c >> 6)); - buf_.push_back(0x80 | (c & 0x3F)); + exposition_only_buf_.push_back(0xC0 | (c >> 6)); + exposition_only_buf_.push_back(0x80 | (c & 0x3F)); } else if (bits <= 16) { - buf_.push_back(0xE0 | (c >> 12)); - buf_.push_back(0x80 | ((c >> 6) & 0x3F)); - buf_.push_back(0x80 | (c & 0x3F)); + exposition_only_buf_.push_back(0xE0 | (c >> 12)); + exposition_only_buf_.push_back(0x80 | ((c >> 6) & 0x3F)); + exposition_only_buf_.push_back(0x80 | (c & 0x3F)); } else { - buf_.push_back(0xF0 | ((c >> 18) & 0x07)); - buf_.push_back(0x80 | ((c >> 12) & 0x3F)); - buf_.push_back(0x80 | ((c >> 6) & 0x3F)); - buf_.push_back(0x80 | (c & 0x3F)); + exposition_only_buf_.push_back(0xF0 | ((c >> 18) & 0x07)); + exposition_only_buf_.push_back(0x80 | ((c >> 12) & 0x3F)); + exposition_only_buf_.push_back(0x80 | ((c >> 6) & 0x3F)); + exposition_only_buf_.push_back(0x80 | (c & 0x3F)); } } else { static_assert(false); @@ -740,8 +740,8 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego }; constexpr read_reverse_impl_result read_reverse_utf8() const { - assert(current_ != begin()); - auto it{current_}; + assert(exposition_only_current_ != begin()); + auto it{exposition_only_current_}; auto const orig{it}; unsigned reversed{}; do { @@ -811,8 +811,8 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego } constexpr read_reverse_impl_result read_reverse_utf16() const { - assert(current_ != begin()); - auto it{current_}; + assert(exposition_only_current_ != begin()); + auto it{exposition_only_current_}; auto const orig{it}; --it; if (detail::high_surrogate(*it)) { @@ -851,8 +851,8 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego } constexpr read_reverse_impl_result read_reverse_utf32() const { - assert(current_ != begin()); - auto it{current_}; + assert(exposition_only_current_ != begin()); + auto it{exposition_only_current_}; auto const orig{it}; --it; auto new_curr{orig}; @@ -876,12 +876,12 @@ struct to_utf_view::exposition_only_iterator : detail::iter_catego update(read_reverse_impl_result.decode_result.c, read_reverse_impl_result.decode_result.to_incr); success_ = read_reverse_impl_result.decode_result.success; - current_ = read_reverse_impl_result.new_curr; - assert(buf_.size()); - buf_index_ = buf_.size() - 1; + exposition_only_current_ = read_reverse_impl_result.new_curr; + assert(exposition_only_buf_.size()); + exposition_only_buf_index_ = exposition_only_buf_.size() - 1; if constexpr (E == to_utf_view_kind::expected) { if (!success_.has_value()) { - buf_index_ = 0; + exposition_only_buf_index_ = 0; } } } @@ -895,29 +895,29 @@ template struct to_utf_view::exposition_only_sentinel { private: using exposition_only_Base = exposition_only_maybe_const; // @*exposition only*@ - std::ranges::sentinel_t end_ = std::ranges::sentinel_t(); + std::ranges::sentinel_t exposition_only_end_ = std::ranges::sentinel_t(); public: exposition_only_sentinel() = default; constexpr explicit exposition_only_sentinel(std::ranges::sentinel_t end) - : end_{end} + : exposition_only_end_{end} {} constexpr explicit exposition_only_sentinel(exposition_only_sentinel i) requires Const && std::convertible_to, std::ranges::sentinel_t> - : end_{i.end_} + : exposition_only_end_{i.exposition_only_end_} {} constexpr std::ranges::sentinel_t base() const { - return end_; + return exposition_only_end_; } template requires std::sentinel_for, std::ranges::iterator_t>> friend constexpr bool operator==(const exposition_only_iterator& x, const exposition_only_sentinel& y) { if constexpr (std::ranges::forward_range) { - return x.current_ == y.end_; + return x.exposition_only_current_ == y.exposition_only_end_; } else { - return x.current_ == y.end_ && x.buf_index_ == -1; + return x.exposition_only_current_ == y.exposition_only_end_ && x.exposition_only_buf_index_ == -1; } } }; diff --git a/papers/P2728.md b/papers/P2728.md index 276885b7..fba6645e 100644 --- a/papers/P2728.md +++ b/papers/P2728.md @@ -782,15 +782,15 @@ public: using difference_type = ptrdiff_t; private: - iterator_t<@*Base*@> begin_{}; // @*exposition only*@, present only if + iterator_t<@*Base*@> @*begin_*@{}; // @*exposition only*@, present only if // bidirectional_range<@*Base*@> is true - iterator_t<@*Base*@> current_{}; // @*exposition only*@ - sentinel_t<@*Base*@> end_; // @*exposition only*@ + iterator_t<@*Base*@> @*current_*@{}; // @*exposition only*@ + sentinel_t<@*Base*@> @*end_*@; // @*exposition only*@ - inplace_vector buf_{}; // @*exposition only*@ + inplace_vector @*buf_*@{}; // @*exposition only*@ - int8_t buf_index_{}; // @*exposition only*@ - uint8_t to_increment_{}; // @*exposition only*@ + int8_t @*buf_index_*@{}; // @*exposition only*@ + uint8_t @*to_increment_*@{}; // @*exposition only*@ template requires view && @*code-unit*@> @@ -807,29 +807,34 @@ public: private: constexpr @*iterator*@(iterator_t<@*Base*@> begin, iterator_t<@*Base*@> current, sentinel_t<@*Base*@> end) // @*exposition only*@ requires bidirectional_range<@*Base*@> - : begin_(std::move(begin)), current_(std::move(current)), end_(end) { - if (current_ != @*end*@()) + : @*begin_*@(std::move(begin)), @*current_*@(std::move(current)), @*end_*@(end) { + if (@*current_*@ != @*end*@()) @*read*@(); } constexpr @*iterator*@(iterator_t<@*Base*@> current, sentinel_t<@*Base*@> end) // @*exposition only*@ requires (!bidirectional_range<@*Base*@>) - : current_(std::move(current)), end_(end) { - if (current_ != @*end*@()) + : @*current_*@(std::move(current)), @*end_*@(end) { + if (@*current_*@ != @*end*@()) @*read*@(); else if constexpr (!forward_range<@*Base*@>) { - buf_index_ = -1; + @*buf_index_*@ = -1; } } public: constexpr const iterator_t<@*Base*@>& base() const& noexcept requires forward_range<@*Base*@> - { return current_; } + { return @*current_*@; } constexpr iterator_t<@*Base*@> base() && requires forward_range<@*Base*@> - { return std::move(current_); } + { return std::move(@*current_*@); } + + constexpr auto base_code_units() const requires forward_range<@*Base*@> + { + return subrange(@*current_*@, next(@*current_*@, @*to_increment_*@)); + } constexpr value_type operator*() const; @@ -863,10 +868,10 @@ public: constexpr @*iterator*@& operator--() requires bidirectional_range<@*Base*@> { - if (!buf_index_) + if (!@*buf_index_*@) @*read-reverse*@(); else - --buf_index_; + --@*buf_index_*@; return *this; } @@ -879,28 +884,28 @@ public: friend constexpr bool operator==(const @*iterator*@& lhs, const @*iterator*@& rhs) requires equality_comparable> { - return lhs.current_ == rhs.current_ && lhs.buf_index_ == rhs.buf_index_; + return lhs.@*current_*@ == rhs.@*current_*@ && lhs.@*buf_index_*@ == rhs.@*buf_index_*@; } private: constexpr sentinel_t<@*Base*@> @*end*@() const { // @*exposition only*@ - return end_; + return @*end_*@; } constexpr expected @*success*@() const noexcept requires(E == to_utf_view_kind::expected); // @*exposition only*@ constexpr void @*advance-one*@() // @*exposition only*@ { - ++buf_index_; - if (buf_index_ == buf_.size()) { + ++@*buf_index_*@; + if (@*buf_index_*@ == @*buf_*@.size()) { if constexpr (forward_range<@*Base*@>) { - buf_index_ = 0; - advance(current_, to_increment_); + @*buf_index_*@ = 0; + advance(@*current_*@, @*to_increment_*@); } - if (current_ != @*end*@()) { + if (@*current_*@ != @*end*@()) { @*read*@(); } else if constexpr (!forward_range<@*Base*@>) { - buf_index_ = -1; + @*buf_index_*@ = -1; } } } @@ -921,7 +926,7 @@ corresponding to `@*from-type*@`. If the underlying range contains ill-formed UTF, the code units are divided into input subsequences according to Substitution of Maximal Subparts, and each ill-formed input subsequence is transcoded into a `U+FFFD`. `c` is then encoded to `ToType`'s corresponding -encoding, into an internal code unit buffer `buf_`. +encoding, into an internal code unit buffer `@*buf_*@`. ::: @@ -954,7 +959,7 @@ In that case, `to_utf_view::@*iterator*@::iterator_category` is defined as follo constexpr value_type operator*() const; ``` -_Returns_: Either `buf_[buf_index_]`, or, if `E` is `to_utf_view_kind::expected` and `!@*success*@()`, then `unexpected{@*success*@().error()}` +_Returns_: Either `@*buf_*@[@*buf_index_*@]`, or, if `E` is `to_utf_view_kind::expected` and `!@*success*@()`, then `unexpected{@*success*@().error()}` ```cpp constexpr expected @*success*@() const noexcept requires(E == to_utf_view_kind::expected); // @*exposition only*@ @@ -1006,12 +1011,12 @@ constexpr void @*read*@(); // @*exposition only*@ _Effects_: -Decodes the input subsequence starting at position `current_` into a code point +Decodes the input subsequence starting at position `@*current_*@` into a code point `c`, using the UTF encoding corresponding to `@*from-type*@`, and setting `c` -to U+FFFD if the input subsequence is ill-formed. It sets `to_increment_` to -the number of code units read while decoding `c`. encodes `c` into `buf_` in -the UTF encoding corresponding to `ToType`, and sets `buf_index_` to `0`. If -`forward_range<@*Base*@>` is modeled, `current_` is set to the position it had +to U+FFFD if the input subsequence is ill-formed. It sets `@*to_increment_*@` to +the number of code units read while decoding `c`. encodes `c` into `@*buf_*@` in +the UTF encoding corresponding to `ToType`, and sets `@*buf_index_*@` to `0`. If +`forward_range<@*Base*@>` is modeled, `@*current_*@` is set to the position it had before `@*read*@` was called. ```cpp @@ -1020,12 +1025,12 @@ constexpr void @*read-reverse*@(); // @*exposition only*@ _Effects_: -Decodes the input subsequence ending at position `current_` into a code point +Decodes the input subsequence ending at position `@*current_*@` into a code point `c`, using the UTF encoding corresponding to `@*from-type*@`, and setting `c` -to U+FFFD if the input subsequence is ill-formed. It sets `to_increment_` to -the number of code units read while decoding `c`; encodes `c` into `buf_` in -the UTF encoding corresponding to `ToType`; and sets `buf_index_` to -`buf_.size() - 1`, or to `0` if this is an `or_error` view and we read an +to U+FFFD if the input subsequence is ill-formed. It sets `@*to_increment_*@` to +the number of code units read while decoding `c`; encodes `c` into `@*buf_*@` in +the UTF encoding corresponding to `ToType`; and sets `@*buf_index_*@` to +`@*buf_*@.size() - 1`, or to `0` if this is an `or_error` view and we read an invalid subsequence. #### 25.7.?.7 Class `to_utf_view::@*sentinel*@` [range.transcoding.sentinel] {-} @@ -1038,24 +1043,24 @@ struct to_utf_view::@*sentinel*@ { private: using @*Base*@ = @*maybe-const*@; // @*exposition only*@ - sentinel_t<@*Base*@> end_ = sentinel_t<@*Base*@>(); // @*exposition only*@ + sentinel_t<@*Base*@> @*end_*@ = sentinel_t<@*Base*@>(); // @*exposition only*@ public: @*sentinel*@() = default; - constexpr explicit @*sentinel*@(sentinel_t<@*Base*@> end) : end_{end} {} + constexpr explicit @*sentinel*@(sentinel_t<@*Base*@> end) : @*end_*@{end} {} constexpr explicit @*sentinel*@(@*sentinel*@ i) requires Const && convertible_to, sentinel_t<@*Base*@>> - : end_{i.end_} {} + : @*end_*@{i.@*end_*@} {} - constexpr sentinel_t<@*Base*@> base() const { return end_; } + constexpr sentinel_t<@*Base*@> base() const { return @*end_*@; } template requires sentinel_for, iterator_t<@*maybe-const*@>> friend constexpr bool operator==(const @*iterator*@& x, const @*sentinel*@& y) { if constexpr (forward_range<@*Base*@>) { - return x.current_ == y.end_; + return x.@*current_*@ == y.@*end_*@; } else { - return x.current_ == y.end_ && x.buf_index_ == -1; + return x.@*current_*@ == y.@*end_*@ && x.@*buf_index_*@ == -1; } } }; diff --git a/papers/generator/post_clang_format.py b/papers/generator/post_clang_format.py index 42226f64..29006ae8 100755 --- a/papers/generator/post_clang_format.py +++ b/papers/generator/post_clang_format.py @@ -9,7 +9,10 @@ def convert_snake_to_kebab(text): def snake_to_kebab(match): word = match.group(0) word = word.replace('exposition_only_', '', 1) - kebab_case_word = word.replace('_', '-') + if word[-1] == "_": + kebab_case_word = word + else: + kebab_case_word = word.replace('_', '-') return f"@*{kebab_case_word}*@" pattern = r'\bexposition_only_[a-zA-Z_]+\b'