Documentation

Batteries.Data.String.Basic

theorem String.Pos.ne_zero_of_lt {a : String.Pos} {b : String.Pos} :
a < bb 0

Returns the longest common prefix of two substrings. The returned substring will use the same underlying string as s.

Equations
@[irreducible]

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
@[irreducible]

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.

Equations
  • s.dropPrefix? pre = if (s.commonPrefix pre).bsize = pre.bsize then some { str := s.str, startPos := (s.commonPrefix pre).stopPos, stopPos := s.stopPos } else none

If suff is a suffix of s, i.e. s = t ++ suff, returns the remainder t.

Equations
  • s.dropSuffix? suff = if (s.commonSuffix suff).bsize = suff.bsize then some { str := s.str, startPos := s.startPos, stopPos := (s.commonSuffix suff).startPos } else none

If pre is a prefix of s, i.e. s = pre ++ t, returns the remainder t.

Equations
  • s.dropPrefix? pre = s.toSubstring.dropPrefix? pre

If suff is a suffix of s, i.e. s = t ++ suff, returns the remainder t.

Equations
  • s.dropSuffix? suff = s.toSubstring.dropSuffix? suff

s.stripPrefix pre will remove pre from the beginning of s if it occurs there, or otherwise return s.

Equations

s.stripSuffix suff will remove suff from the end of s if it occurs there, or otherwise return s.

Equations
def String.count (s : String) (c : Char) :

Count the occurrences of a character in a string.

Equations

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
@[irreducible]

Internal implementation of toAsciiByteArray. loop p out = out ++ toAsciiByteArray ({ s with startPos := p } : Substring)

Equations