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
RegExpwith theuflag. Record dialect notes.
Acceptance criteria
- The spec examples are tests, including empty and edge cases (
substringout 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 callsempty()(T0041),select()(T0042) ortoString()(T0014), or ismatchesFull()(T0029); the generated reports list them as "not implemented".
Implementation notes
functions/string.tsdefines the twelve functions. The input and each argument go through singleton evaluation as a String (anIntegerforsubstring()), whether or not another one is empty, so an error does not depend on the data.functions/characters.tsholds the code point arithmetic andfunctions/regex.tsthe regular expressions; both are internal.- The decisions are in spec notes: characters are Unicode scalar values, regular expressions are JavaScript's with the
uandsflags, the substitution ofreplaceMatches()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
flagsparameter tomatches()andreplaceMatches():compileRegex()already takes the flags, and an optional parameter does not change the calls written today.