Skip to content

Commit

Permalink
Editorial: clean up ambiguous usages of string's "length" and "offset"
Browse files Browse the repository at this point in the history
This change is a follow-up to a9ef15d in aligning the HTML spec with the string changes in Infra (see whatwg/infra#291). In particular, it changes existing usages of "length" which didn't link to either of the Infra definitions, and it updates usages of offsets to have them refer to the string's code unit representation.

As part of updating the usage of offsets in form control algorithms, this change also removes text which is no longer normative or turns it into a note.
  • Loading branch information
Andreu Botella committed Mar 11, 2020
1 parent a9ef15d commit 400de44
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
it.</p>

<p>The term <dfn data-x="">empty</dfn>, when used for an attribute value, <code>Text</code> node,
or string, means that the length of the text is zero (i.e., not even containing <span
or string, means that the <span>length</span> of the text is zero (i.e., not even containing <span
data-x="control">controls</span> or U+0020 SPACE).</p>

<p>A <dfn data-x="nodes are inserted">node <var>A</var> is inserted</dfn> into a node <var>B</var>
Expand Down Expand Up @@ -6539,9 +6539,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<li>

<p>If <var>input</var> is four characters long, and the first character in <var>input</var> is
U+0023 (#), and the last three characters of <var>input</var> are all <span>ASCII hex
digits</span>, then:</p>
<p>If <var>input</var>'s <span>code point length</span> is four, and the first character in
<var>input</var> is U+0023 (#), and the last three characters of <var>input</var> are all
<span>ASCII hex digits</span>, then:</p>

<ol>

Expand All @@ -6562,24 +6562,25 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

</li>

<li><p>Replace any characters in <var>input</var> that have a code point greater than U+FFFF
(i.e., any characters that are not in the basic multilingual plane) with the two-character string
"<code data-x="">00</code>".</p></li>
<li><p>Replace any <span data-x="code point">code points</span> greater than U+FFFF in
<var>input</var> (i.e., any characters that are not in the basic multilingual plane) with the
two-character string "<code data-x="">00</code>".</p></li>

<li><p>If <var>input</var> is longer than 128 characters, truncate <var>input</var>, leaving only the first 128 characters.</p></li>
<li><p>If <var>input</var>'s <span>code point length</span> is greater than 128, truncate
<var>input</var>, leaving only the first 128 characters.</p></li>

<li><p>If the first character in <var>input</var> is a U+0023 NUMBER SIGN character (#),
remove it.</p></li>

<li><p>Replace any character in <var>input</var> that is not an <span data-x="ASCII hex
digits">ASCII hex digit</span> with the character U+0030 DIGIT ZERO (0).</p></li>

<li><p>While <var>input</var>'s length is zero or not a multiple of three, append a
U+0030 DIGIT ZERO (0) character to <var>input</var>.</p></li>
<li><p>While <var>input</var>'s <span>code point length</span> is zero or not a multiple of
three, append a U+0030 DIGIT ZERO (0) character to <var>input</var>.</p></li>

<li><p>Split <var>input</var> into three strings of equal length, to obtain three
components. Let <var>length</var> be the length of those components (one third the
length of <var>input</var>).</p></li>
<li><p>Split <var>input</var> into three strings of equal <span>code point length</span>, to
obtain three components. Let <var>length</var> be the <span>code point length</span> that all of
those components have (one third the <span>code point length</span> of <var>input</var>).</p></li>

<li><p>If <var>length</var> is greater than 8, then remove the leading <span
data-x=""><var>length</var>-8</span> characters in each component, and let <var>length</var> be 8.</p></li>
Expand Down Expand Up @@ -55766,8 +55767,11 @@ MIT Room 32-G524
data-x="concept-input-apply">apply</span>, and all <code>textarea</code> elements, have either a
<dfn data-x="concept-textarea/input-selection">selection</dfn> or a <dfn
data-x="concept-textarea/input-cursor">text entry cursor position</dfn> at all times (even for
elements that are not <span>being rendered</span>). The initial state must consist of a <span
data-x="concept-textarea/input-cursor">text entry cursor</span> at the beginning of the control.</p>
elements that are not <span>being rendered</span>), measured in offsets into the <span
data-x="code unit">code units</span> of the control's <span
data-x="concept-textarea/input-relevant-value">relevant value</span>. The initial state must
consist of a <span data-x="concept-textarea/input-cursor">text entry cursor</span> at the
beginning of the control.</p>
<!-- Previously the spec said to let platform conventions decide, but the web depends on it being
at the beginning; see https://bugzilla.mozilla.org/show_bug.cgi?id=1337392 -->

Expand Down Expand Up @@ -55797,6 +55801,10 @@ MIT Room 32-G524
data-x="">replacedB</code>".</p>
</div>

<p class="note">Characters with no visible rendering, such as U+200D ZERO WIDTH JOINER, still
count as characters. Thus, for instance, the selection can include just an invisible character,
and the text insertion cursor can be placed to one side or another of such a character.</p>

<p>Whenever the <span data-x="concept-textarea/input-relevant-value">relevant value</span> changes
for an element to which these APIs apply, run these steps:</p>

Expand Down Expand Up @@ -55834,10 +55842,6 @@ MIT Room 32-G524
position</span>, beyond just the clamping steps above. For example, see the <code
data-x="dom-textarea-value">value</code> setter for <code>textarea</code>.</p>

<p>Characters with no visible rendering, such as U+200D ZERO WIDTH JOINER, still count as
characters. Thus, for instance, the selection can include just an invisible character, and the
text insertion cursor can be placed to one side or another of such a character.</p>

<p>Where possible, user interface features for changing the <span
data-x="concept-textarea/input-selection">text selection</span> in <code>input</code> and
<code>textarea</code> elements must be implemented using the <span>set the selection range</span>
Expand Down Expand Up @@ -55899,12 +55903,12 @@ MIT Room 32-G524
not apply</span> to this element, return null.</p></li>

<li><p>If there is no <span data-x="concept-textarea/input-selection">selection</span>, return
the offset (in logical order) within the <span
the <span>code unit</span> offset within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
immediately follows the <span data-x="concept-textarea/input-cursor">text entry
cursor</span>.</p></li>

<li><p>Return the offset (in logical order) within the <span
<li><p>Return the <span>code unit</span> offset within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
immediately follows the start of the <span
data-x="concept-textarea/input-selection">selection</span>.</p></li>
Expand Down Expand Up @@ -55939,12 +55943,12 @@ MIT Room 32-G524
not apply</span> to this element, return null.</p></li>

<li><p>If there is no <span data-x="concept-textarea/input-selection">selection</span>, return
the offset (in logical order) within the <span
the <span>code unit</span> offset within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
immediately follows the <span data-x="concept-textarea/input-cursor">text entry
cursor</span>.</p></li>

<li><p>Return the offset (in logical order) within the <span
<li><p>Return the <span>code unit</span> offset within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> to the character that
immediately follows the end of the <span
data-x="concept-textarea/input-selection">selection</span>.</p></li>
Expand Down Expand Up @@ -56016,11 +56020,11 @@ MIT Room 32-G524
<li><p>If <var>end</var> is null, let <var>end</var> be zero.</p></li>

<li><p>Set the <span data-x="concept-textarea/input-selection">selection</span> of the text
control to the sequence of characters within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> starting with the character
at the <var>start</var>th position (in logical order) and ending with the character at the <span
data-x="">(<var>end</var>-1)</span>th position. Arguments greater than the length of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control
control to the sequence of <span data-x="code unit">code units</span> within the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> starting with the code unit
at the <var>start</var>th position (in logical order) and ending with the code unit at the <span
data-x="">(<var>end</var>-1)</span>th position. Arguments greater than the <span>length</span> of
the <span data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control
(including the special value infinity) must be treated as pointing at the end of the text
control. If <var>end</var> is less than or equal to <var>start</var> then the start of the
selection and the end of the selection must both be placed immediately before the character with
Expand Down Expand Up @@ -56074,32 +56078,34 @@ MIT Room 32-G524
<li><p>If <var>start</var> is greater than <var>end</var>, then throw an
<span>"<code>IndexSizeError</code>"</span> <code>DOMException</code>.</p></li>

<li><p>If <var>start</var> is greater than the length of the <span
<li><p>If <var>start</var> is greater than the <span>length</span> of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control, then
set it to the length of the <span data-x="concept-textarea/input-relevant-value">relevant
value</span> of the text control.</p></li>
set it to the <span>length</span> of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control.</p></li>

<li><p>If <var>end</var> is greater than the length of the <span
<li><p>If <var>end</var> is greater than the <span>length</span> of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control, then
set it to the length of the <span data-x="concept-textarea/input-relevant-value">relevant
value</span> of the text control.</p></li>
set it to the <span>length</span> of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control.</p></li>

<li><p>Let <var>selection start</var> be the current value of the <code
data-x="dom-textarea/input-selectionStart">selectionStart</code> attribute.</p></li>

<li><p>Let <var>selection end</var> be the current value of the <code
data-x="dom-textarea/input-selectionEnd">selectionEnd</code> attribute.</p></li>

<li><p>If <var>start</var> is less than <var>end</var>, delete the sequence of characters within
the element's <span data-x="concept-textarea/input-relevant-value">relevant value</span> starting
with the character at the <var>start</var>th position (in logical order) and ending with the
character at the <span data-x="">(<var>end</var>-1)</span>th position.</p></li>
<li><p>If <var>start</var> is less than <var>end</var>, delete the sequence of <span data-x="code
unit">code units</span> within the element's <span
data-x="concept-textarea/input-relevant-value">relevant value</span> starting with the code unit
at the <var>start</var>th position and ending with the code unit at the <span
data-x="">(<var>end</var>-1)</span>th position.</p></li>

<li><p>Insert the value of the first argument into the text of the <span
data-x="concept-textarea/input-relevant-value">relevant value</span> of the text control,
immediately before the <var>start</var>th character.</p></li>
immediately before the <var>start</var>th <span>code unit</span>.</p></li>

<li><p>Let <var>new length</var> be the length of the value of the first argument.</p></li>
<li><p>Let <var>new length</var> be the <span>length</span> of the value of the first
argument.</p></li>

<li><p>Let <var>new end</var> be the sum of <var>start</var> and <var>new length</var>.</p></li>

Expand Down Expand Up @@ -122738,7 +122744,7 @@ interface <dfn>External</dfn> {
<th> <code data-x="">maxlength</code>
<td> <code data-x="attr-input-maxlength">input</code>;
<code data-x="attr-textarea-maxlength">textarea</code>
<td> Maximum length of value
<td> Maximum <span>length</span> of value
<td> <span>Valid non-negative integer</span>
<tr>
<th> <code data-x="">media</code>
Expand Down Expand Up @@ -122768,7 +122774,7 @@ interface <dfn>External</dfn> {
<th> <code data-x="">minlength</code>
<td> <code data-x="attr-input-minlength">input</code>;
<code data-x="attr-textarea-minlength">textarea</code>
<td> Minimum length of value
<td> Minimum <span>length</span> of value
<td> <span>Valid non-negative integer</span>
<tr>
<th> <code data-x="">multiple</code>
Expand Down

0 comments on commit 400de44

Please sign in to comment.