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: Refactor PartitionPattern for simplicity and comprehensibility #840

Merged
merged 1 commit into from
Apr 29, 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
31 changes: 14 additions & 17 deletions spec/negotiation.html
Original file line number Diff line number Diff line change
Expand Up @@ -435,29 +435,26 @@ <h1>
<dl class="header">
<dt>description</dt>
<dd>
The [[Value]] field will be a String value if [[Type]] is *"literal"*, and *undefined* otherwise.
It interprets _pattern_ as containing an arbitrary number of brace-wrapped "placeholder" <emu-not-ref>substrings</emu-not-ref> and returns a List in which each such placeholder is represented as a Record with [[Type]] equal to the unwrapped <emu-not-ref>substring</emu-not-ref> and [[Value]] equal to *undefined*, and each non-empty <emu-not-ref>substring</emu-not-ref> adjacent to or between such placeholders is represented as a Record with [[Type]] equal to *"literal"* and [[Value]] equal to the <emu-not-ref>substring</emu-not-ref>, preserving the relative order of appearance such that _pattern_ could be recovered by concatenating the value from the appropriate field of each Record in turn.
The syntax of the abstract pattern strings is an implementation detail and is not exposed to users of ECMA-402.
</dd>
</dl>
<emu-alg>
1. Let _result_ be a new empty List.
1. Let _beginIndex_ be StringIndexOf(_pattern_, *"{"*, 0).
1. Let _endIndex_ be 0.
1. Let _nextIndex_ be 0.
1. Let _length_ be the number of code units in _pattern_.
1. Repeat, while _beginIndex_ is an integer index into _pattern_,
1. Set _endIndex_ to StringIndexOf(_pattern_, *"}"*, _beginIndex_).
1. Assert: _endIndex_ is greater than _beginIndex_.
1. If _beginIndex_ is greater than _nextIndex_, then
1. Let _literal_ be a substring of _pattern_ from position _nextIndex_, inclusive, to position _beginIndex_, exclusive.
1. Let _placeholderEnd_ be -1.
1. Let _placeholderStart_ be StringIndexOf(_pattern_, *"{"*, 0).
1. Repeat, while _placeholderEnd_ < _placeholderStart_,
1. Let _literal_ be the substring of _pattern_ from _placeholderEnd_ + 1 to _placeholderStart_.
1. If _literal_ is not the empty String, then
1. Append the Record { [[Type]]: *"literal"*, [[Value]]: _literal_ } to _result_.
1. Let _p_ be the substring of _pattern_ from position _beginIndex_, exclusive, to position _endIndex_, exclusive.
1. Append the Record { [[Type]]: _p_, [[Value]]: *undefined* } to _result_.
1. Set _nextIndex_ to _endIndex_ + 1.
1. Set _beginIndex_ to StringIndexOf(_pattern_, *"{"*, _nextIndex_).
1. If _nextIndex_ is less than _length_, then
1. Let _literal_ be the substring of _pattern_ from position _nextIndex_, inclusive, to position _length_, exclusive.
1. Append the Record { [[Type]]: *"literal"*, [[Value]]: _literal_ } to _result_.
1. Set _placeholderEnd_ to StringIndexOf(_pattern_, *"}"*, _placeholderStart_).
1. Assert: _placeholderStart_ < _placeholderEnd_.
1. Let _placeholderName_ be the substring of _pattern_ from _placeholderStart_ + 1 to _placeholderEnd_.
1. Append the Record { [[Type]]: _placeholderName_, [[Value]]: *undefined* } to _result_.
1. Set _placeholderStart_ to StringIndexOf(_pattern_, *"{"*, _placeholderEnd_).
1. Let _tail_ be the substring of _pattern_ from _placeholderEnd_ + 1.
1. If _tail_ is not the empty String, then
1. Append the Record { [[Type]]: *"literal"*, [[Value]]: _tail_ } to _result_.
1. Return _result_.
</emu-alg>
</emu-clause>
Expand Down
Loading