Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 6fc628f

Browse files
committed
fixup: review feedback
1 parent a293f72 commit 6fc628f

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

spec.emu

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,54 @@ contributors: Jordan Harband
2727
<emu-alg>
2828
1. Let _str_ be ? ToString(_S_).
2929
1. Let _cpList_ be StringToCodePoints(_str_).
30-
1. Let _punctuators_ be the following String, which consists of every ASCII punctuator except U+005F (LOW LINE): *"(){}[]|,.?\*+-^$=<>\/#&!%:;@~'"`"*.
31-
1. Let _toEscape_ be StringToCodePoints(_punctuators_).
3230
1. Let _escapedList_ be a new empty List.
3331
1. For each code point _c_ in _cpList_, do
3432
1. If _escapedList_ is empty and _c_ is matched by |DecimalDigit|, then
3533
1. Append code unit U+005C (REVERSE SOLIDUS) to _escapedList_.
3634
1. Append code unit U+0078 (LATIN SMALL LETTER X) to _escapedList_.
3735
1. Append code unit U+0033 (DIGIT THREE) to _escapedList_.
3836
1. Append _c_ to _escapedList_.
39-
1. Else if _toEscape_ contains _c_ or _c_ is matched by |WhiteSpace|, then
40-
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
41-
1. If the length of _hex_ is 1 or 2, then
42-
1. Set _hex_ to StringPad(_hex_, 2, *"0"*, ~start~).
43-
1. Append code unit U+0078 (LATIN SMALL LETTER X) to _escapedList_.
44-
1. Append the code units in _hex_ to _escapedList_.
45-
1. Else,
46-
1. Assert: The length of _hex_ is at most 4.
47-
1. Set _hex_ to StringPad(_hex_, 4, *"0"*, ~start~).
48-
1. Append code unit U+0075 (LATIN SMALL LETTER U) to _escapedList_.
49-
1. Append the code units in _hex_ to _escapedList_.
5037
1. Else,
51-
1. Append _c_ to _escapedList_.
38+
1. Append the code units in EncodeForRegExpEscape(_c_) to _escapedList_.
5239
1. Return CodePointsToString(_escapedList_).
5340
</emu-alg>
5441

5542
<emu-note>
5643
<p>`escape` takes a string and escapes it so it can be literally represented as a pattern. In contrast EscapeRegExpPattern (as the name implies) takes a pattern and escapes it so that it can be represented as a string. While the two are related, they do not share the same character escape set or perform similar actions.</p>
5744
</emu-note>
5845
</emu-clause>
46+
47+
<emu-clause id="sec-encode" type="abstract operation">
48+
<h1>
49+
EncodeForRegExpEscape (
50+
_c_: a code unit,
51+
): a List of code units
52+
</h1>
53+
<dl class="header">
54+
<dt>description</dt>
55+
<dd>If the code unit represents a RegExp punctuator that needs escaping, or ASCII whitespace, it produces the code units for *"\x"* followed by the relevant escape code. If the code unit represents non-ASCII white space, it produces the code units for *"\u"* followed by the relevant escape code. Otherwise, it returns a List containing the original code unit.</dd>
56+
</dl>
57+
58+
<emu-alg>
59+
1. Let _codeUnits_ be a new empty List.
60+
1. Let _punctuators_ be the following String, which consists of every ASCII punctuator except U+005F (LOW LINE): *"(){}[]|,.?\*+-^$=<>\/#&!%:;@~'"`"*.
61+
1. Let _toEscape_ be StringToCodePoints(_punctuators_).
62+
1. If _toEscape_ contains _c_ or _c_ is matched by |WhiteSpace|, then
63+
1. Append code unit U+005C (REVERSE SOLIDUS) to _codeUnits_.
64+
1. Let _hex_ be Number::toString(𝔽(_c_), 16).
65+
1. If the length of _hex_ is 1 or 2, then
66+
1. Set _hex_ to StringPad(_hex_, 2, *"0"*, ~start~).
67+
1. Append code unit U+0078 (LATIN SMALL LETTER X) to _codeUnits_.
68+
1. Else,
69+
1. Assert: The length of _hex_ is at most 4.
70+
1. Set _hex_ to StringPad(_hex_, 4, *"0"*, ~start~).
71+
1. Append code unit U+0075 (LATIN SMALL LETTER U) to _codeUnits_.
72+
1. Append the code units in _hex_ to _codeUnits_.
73+
1. Else,
74+
1. Append _c_ to _codeUnits_.
75+
1. Return _codeUnits_.
76+
</emu-alg>
77+
</emu-clause>
5978
</ins>
6079
</emu-clause>
6180
</emu-clause>

0 commit comments

Comments
 (0)