Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: make String{,Last}IndexOf return not-found #3300

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ <h1>
_string_: a String,
_searchValue_: a String,
_fromIndex_: a non-negative integer,
): a non-negative integer or -1
): a non-negative integer or ~not-found~
</h1>
<dl class="header">
</dl>
Expand All @@ -1163,13 +1163,13 @@ <h1>
1. For each integer _i_ such that _fromIndex_ ≤ _i_ ≤ _len_ - _searchLen_, in ascending order, do
1. Let _candidate_ be the substring of _string_ from _i_ to _i_ + _searchLen_.
1. If _candidate_ is _searchValue_, return _i_.
1. Return -1.
1. Return ~not-found~.
</emu-alg>
<emu-note>
<p>If _searchValue_ is the empty String and _fromIndex_ ≤ the length of _string_, this algorithm returns _fromIndex_. The empty String is effectively found at every position within a string, including after the last code unit.</p>
</emu-note>
<emu-note>
<p>This algorithm always returns -1 if _fromIndex_ + the length of _searchValue_ > the length of _string_.</p>
<p>This algorithm always returns ~not-found~ if _fromIndex_ + the length of _searchValue_ > the length of _string_.</p>
</emu-note>
</emu-clause>

Expand All @@ -1179,7 +1179,7 @@ <h1>
_string_: a String,
_searchValue_: a String,
_fromIndex_: a non-negative integer,
): a non-negative integer or -1
): a non-negative integer or ~not-found~
</h1>
<dl class="header">
</dl>
Expand All @@ -1190,7 +1190,7 @@ <h1>
1. For each integer _i_ such that 0 ≤ _i_ ≤ _fromIndex_, in descending order, do
1. Let _candidate_ be the substring of _string_ from _i_ to _i_ + _searchLen_.
1. If _candidate_ is _searchValue_, return _i_.
1. Return -1.
1. Return ~not-found~.
</emu-alg>
<emu-note>
<p>If _searchValue_ is the empty String, this algorithm returns _fromIndex_. The empty String is effectively found at every position within a string, including after the last code unit.</p>
Expand Down Expand Up @@ -34605,8 +34605,8 @@ <h1>String.prototype.includes ( _searchString_ [ , _position_ ] )</h1>
1. Let _len_ be the length of _S_.
1. Let _start_ be the result of clamping _pos_ between 0 and _len_.
1. Let _index_ be StringIndexOf(_S_, _searchStr_, _start_).
1. If _index_ ≠ -1, return *true*.
1. Return *false*.
1. If _index_ is ~not-found~, return *false*.
1. Return *true*.
</emu-alg>
<emu-note>
<p>If _searchString_ appears as a <emu-not-ref>substring</emu-not-ref> of the result of converting this object to a String, at one or more indices that are greater than or equal to _position_, this function returns *true*; otherwise, it returns *false*. If _position_ is *undefined*, 0 is assumed, so as to search all of the String.</p>
Expand All @@ -34633,7 +34633,9 @@ <h1>String.prototype.indexOf ( _searchString_ [ , _position_ ] )</h1>
1. Assert: If _position_ is *undefined*, then _pos_ is 0.
1. Let _len_ be the length of _S_.
1. Let _start_ be the result of clamping _pos_ between 0 and _len_.
1. Return 𝔽(StringIndexOf(_S_, _searchStr_, _start_)).
1. Let _result_ be StringIndexOf(_S_, _searchStr_, _start_).
1. If _result_ is ~not-found~, return *-1*<sub>𝔽</sub>.
1. Return 𝔽(_result_).
</emu-alg>
<emu-note>
<p>This method is intentionally generic; it does not require that its *this* value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
Expand Down Expand Up @@ -34666,7 +34668,9 @@ <h1>String.prototype.lastIndexOf ( _searchString_ [ , _position_ ] )</h1>
1. Let _len_ be the length of _S_.
1. Let _searchLen_ be the length of _searchStr_.
1. Let _start_ be the result of clamping _pos_ between 0 and _len_ - _searchLen_.
1. Return 𝔽(StringLastIndexOf(_S_, _searchStr_, _start_)).
1. Let _result_ be StringLastIndexOf(_S_, _searchStr_, _start_).
1. If _result_ is ~not-found~, return *-1*<sub>𝔽</sub>.
1. Return 𝔽(_result_).
</emu-alg>
<emu-note>
<p>This method is intentionally generic; it does not require that its *this* value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.</p>
Expand Down Expand Up @@ -34896,7 +34900,7 @@ <h1>String.prototype.replace ( _searchValue_, _replaceValue_ )</h1>
1. Set _replaceValue_ to ? ToString(_replaceValue_).
1. Let _searchLength_ be the length of _searchString_.
1. Let _position_ be StringIndexOf(_string_, _searchString_, 0).
1. If _position_ = -1, return _string_.
1. If _position_ is ~not-found~, return _string_.
1. Let _preceding_ be the substring of _string_ from 0 to _position_.
1. Let _following_ be the substring of _string_ from _position_ + _searchLength_.
1. If _functionalReplace_ is *true*, then
Expand Down Expand Up @@ -34970,7 +34974,7 @@ <h1>
1. Let _refReplacement_ be _ref_.
1. Else if _templateRemainder_ starts with *"$&lt;"*, then
1. Let _gtPos_ be StringIndexOf(_templateRemainder_, *">"*, 0).
1. If _gtPos_ = -1 or _namedCaptures_ is *undefined*, then
1. If _gtPos_ is ~not-found~ or _namedCaptures_ is *undefined*, then
1. Let _ref_ be *"$&lt;"*.
1. Let _refReplacement_ be _ref_.
1. Else,
Expand Down Expand Up @@ -35016,7 +35020,7 @@ <h1>String.prototype.replaceAll ( _searchValue_, _replaceValue_ )</h1>
1. Let _advanceBy_ be max(1, _searchLength_).
1. Let _matchPositions_ be a new empty List.
1. Let _position_ be StringIndexOf(_string_, _searchString_, 0).
1. Repeat, while _position_ ≠ -1,
1. Repeat, while _position_ is not ~not-found~,
1. Append _position_ to _matchPositions_.
1. Set _position_ to StringIndexOf(_string_, _searchString_, _position_ + _advanceBy_).
1. Let _endOfLastMatch_ be 0.
Expand Down Expand Up @@ -35105,7 +35109,7 @@ <h1>String.prototype.split ( _separator_, _limit_ )</h1>
1. Let _substrings_ be a new empty List.
1. Let _i_ be 0.
1. Let _j_ be StringIndexOf(_S_, _R_, 0).
1. Repeat, while _j_ ≠ -1,
1. Repeat, while _j_ is not ~not-found~,
1. Let _T_ be the substring of _S_ from _i_ to _j_.
1. Append _T_ to _substrings_.
1. If the number of elements in _substrings_ is _lim_, return CreateArrayFromList(_substrings_).
Expand Down
Loading