Skip to content

Commit

Permalink
Add "starts with" synonym for "code unit prefix"
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed May 3, 2019
1 parent 7151ce3 commit 339be9b
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -543,37 +543,49 @@ actually ends up representing <a lt="JavaScript string">JavaScript</a> and
<a>scalar value strings</a>. It is even fairly typical for implementations to have multiple
implementations of just <a>JavaScript strings</a> for performance and memory reasons.

<p>A <a>string</a> <var>a</var> is a <dfn export>code unit prefix</dfn> of a <a>string</a>
<var>b</var> if the following steps return true:</p>
<hr>

<p>A <a>string</a> <var>a</var> is a
<dfn export lt="code unit prefix|starts with">code unit prefix</dfn> of a <a>string</a> <var>b</var>
if the following steps return true:

<ol>
<li><p>Let <var>i</var> be 0.</p></li>
<li><p>Let <var>i</var> be 0.

<li>
<p><a>While</a> true:</p>
<p><a>While</a> true:

<ol>
<li><p>Let <var>aCodeUnit</var> be the <var>i</var>th <a>code unit</a> of <var>a</var>, or null
if <var>i</var> is greater than or equal to <var>a</var>'s <a for=string>length</a>.</p></li>
if <var>i</var> is greater than or equal to <var>a</var>'s <a for=string>length</a>.

<li><p>Let <var>bCodeUnit</var> be the <var>i</var>th <a>code unit</a> of <var>b</var>, or null
if <var>i</var> is greater than or equal to <var>b</var>'s <a for=string>length</a>.</p></li>
if <var>i</var> is greater than or equal to <var>b</var>'s <a for=string>length</a>.

<li><p>If both <var>aCodeUnit</var> and <var>bCodeUnit</var> are null, then return true.</p></li>
<li><p>If both <var>aCodeUnit</var> and <var>bCodeUnit</var> are null, then return true.

<li><p>If <var>aCodeUnit</var> is null and <var>bCodeUnit</var> is non-null, then return
true.</p></li>
true.

<li><p>If <var>aCodeUnit</var> is non-null and <var>bCodeUnit</var> is null, then return
false.</p></li>
false.

<li><p>Return false if <var>aCodeUnit</var> is different from <var>bCodeUnit</var>.</p></li>
<li><p>Return false if <var>aCodeUnit</var> is different from <var>bCodeUnit</var>.

<li><p>Set <var>i</var> to <var>i</var> + 1.</p></li>
<li><p>Set <var>i</var> to <var>i</var> + 1.
</ol>
</li>
</ol>

<p>When it is clear from context that <a>code units</a> are in play, e.g., because one of the
strings is a literal containing only characters that are in the range U+0020 SPACE to U+007E (~),
"<var>a</var> starts with <var>b</var>" can be used as a synonym for "<var>b</var> is a
<a>code unit prefix</a> of <var>a</var>".

<p class=example id=code-unit-prefix-example>With unknown values, it is good to be explicit:
<var>targetString</var> is a <a>code unit prefix</a> of <var>userInput</var>. But with a literal,
we can use plainer language: <var>userInput</var> starts with "<code>!</code>".

<p>A <a>string</a> <var>a</var> is <dfn export>code unit less than</dfn> a <a>string</a>
<var>b</var> if the following steps return true:

Expand Down

0 comments on commit 339be9b

Please sign in to comment.