|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4287" status="New"> |
| 5 | +<title>§[locale.codecvt.virtuals] `do_in` and `do_out` could do with better specification</title> |
| 6 | +<section> |
| 7 | +<sref ref="[locale.codecvt.virtuals]"/> |
| 8 | +</section> |
| 9 | +<submitter>S. B. Tam</submitter> |
| 10 | +<date>18 Jun 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +Background: <a href="https://github.com/cplusplus/draft/pull/7347">https://github.com/cplusplus/draft/pull/7347</a> |
| 16 | +<p/> |
| 17 | +The specification of `codecvt::do_in` and `codecvt::do_out` is unclear, and possibly incorrect: |
| 18 | +</p> |
| 19 | +<ol> |
| 20 | +<li><p>the meaning of `noconv` is specified twice (once in paragraph 3, once in Table 91 [tab:locale.codecvt.inout]);</p></li> |
| 21 | +<li><p>the effect on `from_next` is not specified;</p></li> |
| 22 | +<li><p>the specification talks about "the input sequence [from, from_next)", but `from_next` is supposed to be an out parameter. |
| 23 | +I think it should say "[from, from_end)" instead.</p></li> |
| 24 | +</ol> |
| 25 | +</discussion> |
| 26 | + |
| 27 | +<resolution> |
| 28 | +<p> |
| 29 | +This wording is relative to <paper num="N5008"/>. |
| 30 | +</p> |
| 31 | + |
| 32 | +<blockquote class="note"> |
| 33 | +<p> |
| 34 | +[<i>Drafting note</i>: This is modified from Jonathan Wakely's suggestion in |
| 35 | +<a href="https://github.com/cplusplus/draft/pull/7347#issuecomment-2549982495">https://github.com/cplusplus/draft/pull/7347#issuecomment</a>] |
| 36 | +</p> |
| 37 | +</blockquote> |
| 38 | + |
| 39 | +<ol> |
| 40 | +<li><p>In <sref ref="[locale.codecvt.virtuals]"/> remove Table 91 [tab:locale.codecvt.inout] in its entirety:</p> |
| 41 | + |
| 42 | +<blockquote> |
| 43 | +<table border="1"> |
| 44 | +<caption><del>Table 91 — `do_in`/`do_out` result values [tab:locale.codecvt.inout]</del></caption> |
| 45 | +<tr align="center"> |
| 46 | +<th><del>Value</del></th> |
| 47 | +<th><del>Meaning</del></th> |
| 48 | +</tr> |
| 49 | + |
| 50 | +<tr> |
| 51 | +<td> |
| 52 | +<del><tt>ok</tt></del> |
| 53 | +</td> |
| 54 | +<td> |
| 55 | +<del>completed the conversion</del> |
| 56 | +</td> |
| 57 | +</tr> |
| 58 | + |
| 59 | +<tr> |
| 60 | +<td> |
| 61 | +<del><tt>partial</tt></del> |
| 62 | +</td> |
| 63 | +<td> |
| 64 | +<del>not all source characters converted</del> |
| 65 | +</td> |
| 66 | +</tr> |
| 67 | + |
| 68 | +<tr> |
| 69 | +<td> |
| 70 | +<del><tt>error</tt></del> |
| 71 | +</td> |
| 72 | +<td> |
| 73 | +<del>encountered a character in `[from, from_end)` that |
| 74 | +cannot be converted</del> |
| 75 | +</td> |
| 76 | +</tr> |
| 77 | + |
| 78 | +<tr> |
| 79 | +<td> |
| 80 | +<del><tt>noconv</tt></del> |
| 81 | +</td> |
| 82 | +<td> |
| 83 | +<del>`internT` and `externT` are the same type, and input |
| 84 | +sequence is identical to converted sequence</del> |
| 85 | +</td> |
| 86 | +</tr> |
| 87 | + |
| 88 | +</table> |
| 89 | + |
| 90 | +</blockquote> |
| 91 | + |
| 92 | +</li> |
| 93 | + |
| 94 | +<li><p>Modify <sref ref="[locale.codecvt.virtuals]"/> as indicated:</p> |
| 95 | + |
| 96 | +<blockquote> |
| 97 | +<pre> |
| 98 | +result do_out( |
| 99 | + stateT& state, |
| 100 | + const internT* from, const internT* from_end, const internT*& from_next, |
| 101 | + externT* to, externT* to_end, externT*& to_next) const; |
| 102 | + |
| 103 | +result do_in( |
| 104 | + stateT& state, |
| 105 | + const externT* from, const externT* from_end, const externT*& from_next, |
| 106 | + internT* to, internT* to_end, internT*& to_next) const; |
| 107 | +</pre> |
| 108 | +<blockquote> |
| 109 | +<p> |
| 110 | +-1- <i>Preconditions</i>: […] |
| 111 | +<p/> |
| 112 | +-2- <i>Effects</i>: Translates characters in the source range `[from, from_end)`, |
| 113 | +placing the results in sequential positions starting at destination to. Converts |
| 114 | +no more than `(from_end - from)` source elements, and stores no more than |
| 115 | +`(to_end - to)` destination elements. |
| 116 | +<p/> |
| 117 | +-3- <del>Stops if it encounters a character it cannot convert. It always leaves the |
| 118 | +`from_next` and `to_next` pointers pointing one beyond the last element successfully |
| 119 | +converted. If it returns `noconv`, `internT` and `externT` are the same type, and the |
| 120 | +converted sequence is identical to the input sequence `[from, from_next)`, `to_next` |
| 121 | +is set equal to `to`, the value of `state` is unchanged, and there are no changes to |
| 122 | +the values in `[to, to_end)`.</del> |
| 123 | +<ins>If `internT` and `externT` are the same type |
| 124 | +and the converted sequence would be identical to the input sequence |
| 125 | +[`from`, `from_next`), then no elements are converted, the value of `state` is unchanged, |
| 126 | +there are no changes to the values in [`to`, `to_end`), and the result is `noconv`. |
| 127 | +Otherwise, if a character in [`from`,`from_end`) cannot be converted, conversion stops |
| 128 | +at that character and the result is `error`. Otherwise, if all input characters are |
| 129 | +successfully converted and placed in the output range, the result is `ok`. Otherwise, |
| 130 | +the result is `partial`. In all cases, `from_next` is set to point to the first element |
| 131 | +of the input that was not converted, `to_next` is set to point to the first unchanged |
| 132 | +element in the output. [<i>Note</i>: When the result is `noconv`, `from_next` points |
| 133 | +to `from` and `to_next` points to `to`. — <i>end note</i>]</ins> |
| 134 | +<p/> |
| 135 | +-4- A `codecvt` facet that is used by `basic_filebuf` […] |
| 136 | +<p/> |
| 137 | +-5- <i>Returns</i>: <del>An enumeration value, as summarized in Table 91</del> |
| 138 | +<ins>The result as described above</ins>. |
| 139 | +</p> |
| 140 | +</blockquote> |
| 141 | +</blockquote> |
| 142 | +</li> |
| 143 | + |
| 144 | +</ol> |
| 145 | +</resolution> |
| 146 | + |
| 147 | +</issue> |
0 commit comments