Skip to content

Commit

Permalink
Editorial: Introduce StringPad operation backing padStart and padEnd (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 authored and ljharb committed Apr 12, 2019
1 parent e7b55c3 commit bc1efa7
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -28518,47 +28518,42 @@ <h1>String.prototype.padEnd ( _maxLength_ [ , _fillString_ ] )</h1>
<p>When the `padEnd` method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the length of _S_.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the String value consisting solely of the code unit 0x0020 (SPACE).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, return _S_.
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be the String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
1. Return the string-concatenation of _S_ and _truncatedStringFiller_.
1. Return ? StringPad(_O_, _maxLength_, _fillString_, *"end"*).
</emu-alg>
<emu-note>
<p>The first argument _maxLength_ will be clamped such that it can be no smaller than the length of the *this* value.</p>
</emu-note>
<emu-note>
<p>The optional second argument _fillString_ defaults to *" "* (the String value consisting of the code unit 0x0020 SPACE).</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-string.prototype.padstart">
<h1>String.prototype.padStart ( _maxLength_ [ , _fillString_ ] )</h1>
<p>When the `padStart` method is called, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the length of _S_.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the String value consisting solely of the code unit 0x0020 (SPACE).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, return _S_.
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be the String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
1. Return the string-concatenation of _truncatedStringFiller_ and _S_.
1. Return ? StringPad(_O_, _maxLength_, _fillString_, *"start"*).
</emu-alg>
<emu-note>
<p>The first argument _maxLength_ will be clamped such that it can be no smaller than the length of the *this* value.</p>
</emu-note>
<emu-note>
<p>The optional second argument _fillString_ defaults to *" "* (the String value consisting of the code unit 0x0020 SPACE).</p>
</emu-note>

<emu-clause id="sec-stringpad" aoid="StringPad">
<h1>Runtime Semantics: StringPad ( _O_, _maxLength_, _fillString_, _placement_ )</h1>
<p>When the abstract operation StringPad is called with arguments _O_, _maxLength_, _fillString_, and _placement_, the following steps are taken:</p>
<emu-alg>
1. Assert: _placement_ is *"start"* or *"end"*.
1. Let _S_ be ? ToString(_O_).
1. Let _intMaxLength_ be ? ToLength(_maxLength_).
1. Let _stringLength_ be the length of _S_.
1. If _intMaxLength_ is not greater than _stringLength_, return _S_.
1. If _fillString_ is *undefined*, let _filler_ be the String value consisting solely of the code unit 0x0020 (SPACE).
1. Else, let _filler_ be ? ToString(_fillString_).
1. If _filler_ is the empty String, return _S_.
1. Let _fillLen_ be _intMaxLength_ - _stringLength_.
1. Let _truncatedStringFiller_ be the String value consisting of repeated concatenations of _filler_ truncated to length _fillLen_.
1. If _placement_ is *"start"*, return the string-concatenation of _truncatedStringFiller_ and _S_.
1. Else, return the string-concatenation of _S_ and _truncatedStringFiller_.
</emu-alg>
<emu-note>
<p>The argument _maxLength_ will be clamped such that it can be no smaller than the length of _S_.</p>
</emu-note>
<emu-note>
<p>The argument _fillString_ defaults to *" "* (the String value consisting of the code unit 0x0020 SPACE).</p>
</emu-note>
</emu-clause>
</emu-clause>

<emu-clause id="sec-string.prototype.repeat">
Expand Down

0 comments on commit bc1efa7

Please sign in to comment.