Equations
- instCoeStringSubstring_batteries = { coe := String.toSubstring }
Returns the longest common prefix of two substrings.
The returned substring will use the same underlying string as s
.
Equations
- s.commonPrefix t = { str := s.str, startPos := s.startPos, stopPos := Substring.commonPrefix.loop s t s.startPos t.startPos }
Returns the ending position of the common prefix, working up from spos, tpos
.
Equations
- One or more equations did not get rendered due to their size.
Returns the longest common suffix of two substrings.
The returned substring will use the same underlying string as s
.
Equations
- s.commonSuffix t = { str := s.str, startPos := Substring.commonSuffix.loop s t s.stopPos t.stopPos, stopPos := s.stopPos }
Returns the starting position of the common prefix, working down from spos, tpos
.
Equations
- One or more equations did not get rendered due to their size.
If pre
is a prefix of s
, i.e. s = pre ++ t
, returns the remainder t
.
If suff
is a suffix of s
, i.e. s = t ++ suff
, returns the remainder t
.
s.stripPrefix pre
will remove pre
from the beginning of s
if it occurs there,
or otherwise return s
.
Equations
- s.stripPrefix pre = (Option.map Substring.toString (s.dropPrefix? pre)).getD s
s.stripSuffix suff
will remove suff
from the end of s
if it occurs there,
or otherwise return s
.
Equations
- s.stripSuffix suff = (Option.map Substring.toString (s.dropSuffix? suff)).getD s
Convert a string of assumed-ASCII characters into a byte array. (If any characters are non-ASCII they will be reduced modulo 256.)
Note: if you just need the underlying ByteArray
of a non-ASCII string,
use String.toUTF8
.
Equations
- s.toAsciiByteArray = String.toAsciiByteArray.loop s 0 ByteArray.empty
Internal implementation of toAsciiByteArray
.
loop p out = out ++ toAsciiByteArray ({ s with startPos := p } : Substring)
Equations
- String.toAsciiByteArray.loop s p out = if h : s.atEnd p = true then out else let c := s.get p; let_fun this := ⋯; String.toAsciiByteArray.loop s (s.next p) (out.push c.toUInt8)