def text.replace.go
import ezsys@0.1.0.0/src/str.bend as Strimport Base
101# the scan for a nonempty `old`; `skip` characters of a found `old` are
102# still to pass over
103def text.replace.go(
104 txt: String,
105 skip: Nat,
106 +old: String,
107 +new: String
108) -> String:
109 match txt skip:
110 case SNil{} _:
111 SNil{}
112 case SCon{_h, t} 1n+k:
113 text.replace.go(t, k, old, new)
114 case SCon{+h, +t} 0n:
115 text.replace.at(String.starts_with(SCon{h, t}, old), h, new,
116 text.after(old),
117 k => text.replace.go(t, k, old, new))