klyn.String._sliceAssign
method
public static _sliceAssign(text as String, start as Int, stop as Int, sliceStep as Int, hasStart as Boolean, hasStop as Boolean, replacement as String) as String:
Description

Internal helper used by the compiler to implement string slice assignment.

The helper returns a new string because Klyn strings are represented by an immutable runtime buffer. The compiler stores that returned value back into the assignable target (text[a:b] = replacement).

Parameters
ParameterDescription
textSource string.
startRequested start bound.
stopRequested exclusive stop bound.
sliceStepSlice step. Cannot be zero.
hasStartTrue when the source slice explicitly provided a start.
hasStopTrue when the source slice explicitly provided a stop.
replacementReplacement text.
Returns

A new string with the requested slice replaced.

Throws
  • Exception if sliceStep == 0.
  • ValueError if an extended slice replacement has the wrong length.
Example
value = String._sliceAssign("Hello World", 6, 11, 1, true, true, "Klyn!")
assert value == "Hello Klyn!"