From 339be9b2d259eb7926d5d6d2065056c5f131a163 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 3 May 2019 16:58:30 -0400 Subject: [PATCH] Add "starts with" synonym for "code unit prefix" --- infra.bs | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/infra.bs b/infra.bs index 99b8f3c..c4c3b47 100644 --- a/infra.bs +++ b/infra.bs @@ -543,37 +543,49 @@ actually ends up representing JavaScript and scalar value strings. It is even fairly typical for implementations to have multiple implementations of just JavaScript strings for performance and memory reasons. -

A string a is a code unit prefix of a string -b if the following steps return true:

+
+ +

A string a is a +code unit prefix of a string b +if the following steps return true:

    -
  1. Let i be 0.

  2. +
  3. Let i be 0.

  4. -

    While true:

    +

    While true:

    1. Let aCodeUnit be the ith code unit of a, or null - if i is greater than or equal to a's length.

    2. + if i is greater than or equal to a's length.
    3. Let bCodeUnit be the ith code unit of b, or null - if i is greater than or equal to b's length.

    4. + if i is greater than or equal to b's length. -
    5. If both aCodeUnit and bCodeUnit are null, then return true.

    6. +
    7. If both aCodeUnit and bCodeUnit are null, then return true.

    8. If aCodeUnit is null and bCodeUnit is non-null, then return - true.

    9. + true.
    10. If aCodeUnit is non-null and bCodeUnit is null, then return - false.

    11. + false. -
    12. Return false if aCodeUnit is different from bCodeUnit.

    13. +
    14. Return false if aCodeUnit is different from bCodeUnit. -

    15. Set i to i + 1.

    16. +
    17. Set i to i + 1.

+

When it is clear from context that code units 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 (~), +"a starts with b" can be used as a synonym for "b is a +code unit prefix of a". + +

With unknown values, it is good to be explicit: +targetString is a code unit prefix of userInput. But with a literal, +we can use plainer language: userInput starts with "!". +

A string a is code unit less than a string b if the following steps return true: