T0015 — Functions: string manipulation

Part of the roadmap. Phase 1 · wave 4 · size M.

Goal

N1 §5.6: indexOf, substring, startsWith, endsWith, contains, upper, lower, replace, matches, replaceMatches, length, toChars.

Scope

  • Decide whether "characters" means Unicode code points or UTF-16 units. The 3.0.0 examples count a surrogate pair as one character; record the choice in spec-notes.md.
  • Regular expressions use JavaScript RegExp with the u flag. Record dialect notes.

Acceptance criteria

  • The spec examples are tests, including empty and edge cases (substring out of range, ''.length()).
  • Conformance groups: testCase, testToChars, testIndexOf, testSubstring, testStartsWith, testEndsWith, testContainsString, testMatches, testReplaceMatches, testReplace, testLength (except STU cases with regex flags). Every test that does not pass yet calls empty() (T0041), select() (T0042) or toString() (T0014), or is matchesFull() (T0029); the generated reports list them as "not implemented".

Implementation notes

  • functions/string.ts defines the twelve functions. The input and each argument go through singleton evaluation as a String (an Integer for substring()), whether or not another one is empty, so an error does not depend on the data. functions/characters.ts holds the code point arithmetic and functions/regex.ts the regular expressions; both are internal.
  • The decisions are in spec notes: characters are Unicode scalar values, regular expressions are JavaScript's with the u and s flags, the substitution of replaceMatches() takes ${name} and JavaScript's patterns, and an empty regex changes nothing.
  • No new error code: an invalid pattern, or a substitution that refers to a missing group, is eval/invalid-argument. Messages do not repeat the pattern, which can come from input data.
  • T0029 adds the optional flags parameter to matches() and replaceMatches(): compileRegex() already takes the flags, and an optional parameter does not change the calls written today.