Documentation

Init.Data.String.Basic

Equations
Equations
Equations
@[extern lean_string_dec_lt]
instance String.decLt (s₁ : String) (s₂ : String) :
Decidable (s₁ < s₂)
Equations
@[extern lean_string_length]
Equations
@[extern lean_string_push]
def String.push :
Equations
  • String.push _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { data := s }, c => { data := s ++ [c] }

The internal implementation uses dynamic arrays and will perform destructive updates if the String is not shared.

@[extern lean_string_append]
Equations
  • String.append _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { data := a }, { data := b } => { data := a ++ b }

The internal implementation uses dynamic arrays and will perform destructive updates if the String is not shared.

Equations

O(n) in the runtime, where n is the length of the String

@[extern lean_string_utf8_get]
Equations
def String.getOp (self : String) (idx : String.Pos) :
Equations
@[extern lean_string_utf8_set]
Equations
  • String.set _fun_discr _fun_discr _fun_discr = match _fun_discr, _fun_discr, _fun_discr with | { data := s }, i, c => { data := String.utf8SetAux c s 0 i }
def String.modify (s : String) (i : String.Pos) (f : CharChar) :
Equations
@[extern lean_string_utf8_next]
Equations
@[extern lean_string_utf8_prev]
Equations
def String.front (s : String) :
Equations
@[extern lean_string_utf8_at_end]
Equations
partial def String.posOfAux (s : String) (c : Char) (stopPos : String.Pos) (pos : String.Pos) :
@[inline]
def String.posOf (s : String) (c : Char) :
Equations
partial def String.revPosOfAux (s : String) (c : Char) (pos : String.Pos) :
Equations
partial def String.findAux (s : String) (p : CharBool) (stopPos : String.Pos) (pos : String.Pos) :
@[inline]
def String.find (s : String) (p : CharBool) :
Equations
partial def String.revFindAux (s : String) (p : CharBool) (pos : String.Pos) :
Equations
@[inline]
abbrev String.Pos.min (p₁ : String.Pos) (p₂ : String.Pos) :
Equations
Equations

Returns the first position where the two strings differ.

partial def String.firstDiffPos.loop (a : String) (b : String) (stopPos : String.Pos) (i : String.Pos) :
@[extern lean_string_utf8_extract]
Equations
  • String.extract _fun_discr _fun_discr _fun_discr = match _fun_discr, _fun_discr, _fun_discr with | { data := s }, b, e => if b.byteIdx e.byteIdx then { data := [] } else { data := String.extract.go₁ s 0 b e }
Equations
Equations
@[specialize]
partial def String.splitAux (s : String) (p : CharBool) (b : String.Pos) (i : String.Pos) (r : List String) :
@[specialize]
def String.split (s : String) (p : CharBool) :
Equations
partial def String.splitOnAux (s : String) (sep : String) (b : String.Pos) (i : String.Pos) (j : String.Pos) (r : List String) :
def String.splitOn (s : String) (sep : optParam String " ") :
Equations
def String.pushn (s : String) (c : Char) (n : Nat) :
Equations
Equations
Equations
Equations
structure String.Iterator :
Type
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
partial def String.offsetOfPosAux (s : String) (pos : String.Pos) (i : String.Pos) (offset : Nat) :
@[specialize]
def String.foldlAux {α : Type u} (f : αCharα) (s : String) (stopPos : String.Pos) (i : String.Pos) (a : α) :
α
Equations
partial def String.foldlAux.loop {α : Type u} (f : αCharα) (s : String) (stopPos : String.Pos) (i : String.Pos) (a : α) :
α
@[inline]
def String.foldl {α : Type u} (f : αCharα) (init : α) (s : String) :
α
Equations
@[specialize]
def String.foldrAux {α : Type u} (f : Charαα) (a : α) (s : String) (stopPos : String.Pos) (i : String.Pos) :
α
Equations
partial def String.foldrAux.loop {α : Type u} (f : Charαα) (a : α) (s : String) (stopPos : String.Pos) (i : String.Pos) :
α
@[inline]
def String.foldr {α : Type u} (f : Charαα) (init : α) (s : String) :
α
Equations
@[specialize]
def String.anyAux (s : String) (stopPos : String.Pos) (p : CharBool) (i : String.Pos) :
Equations
partial def String.anyAux.loop (s : String) (stopPos : String.Pos) (p : CharBool) (i : String.Pos) :
@[inline]
def String.any (s : String) (p : CharBool) :
Equations
@[inline]
def String.all (s : String) (p : CharBool) :
Equations
def String.contains (s : String) (c : Char) :
Equations
@[specialize]
partial def String.mapAux (f : CharChar) (i : String.Pos) (s : String) :
@[inline]
def String.map (f : CharChar) (s : String) :
Equations
def String.isNat (s : String) :
Equations
Equations
def String.substrEq (s1 : String) (off1 : String.Pos) (s2 : String) (off2 : String.Pos) (sz : Nat) :
Equations

Return true iff the substring of byte size sz starting at position off1 in s1 is equal to that starting at off2 in s2.. False if either substring of that byte size does not exist.

partial def String.substrEq.loop (s1 : String) (s2 : String) (off1 : String.Pos) (off2 : String.Pos) (stop1 : String.Pos) :
def String.isPrefixOf (p : String) (s : String) :
Equations

Return true iff p is a prefix of s

def String.replace (s : String) (pattern : String) (replacement : String) :
Equations

Replace all occurrences of pattern in s with replacment.

partial def String.replace.loop (s : String) (pattern : String) (replacement : String) (acc : String) (accStop : String.Pos) (pos : String.Pos) :
@[inline]
Equations
@[inline]
Equations
@[inline]
Equations
  • Substring.toIterator _fun_discr = match _fun_discr with | { str := s, startPos := b, stopPos := stopPos } => { s := s, i := b }
@[inline]
Equations
  • Substring.get _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := stopPos }, p => String.get s (b + p)

Return the codepoint at the given offset into the substring.

@[inline]
Equations
  • Substring.next _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, p => let absP := b + p; if absP = e then p else { byteIdx := (String.next s absP).byteIdx - b.byteIdx }

Given an offset of a codepoint into the substring, return the offset there of the next codepoint.

@[inline]
Equations
  • Substring.prev _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := stopPos }, p => let absP := b + p; if absP = b then p else { byteIdx := (String.prev s absP).byteIdx - b.byteIdx }

Given an offset of a codepoint into the substring, return the offset there of the previous codepoint.

Equations
Equations
@[inline]
Equations
@[inline]
Equations

Return the offset into s of the first occurence of c in s, or s.bsize if c doesn't occur.

@[inline]
Equations
  • Substring.drop _fun_discr _fun_discr = match _fun_discr, _fun_discr with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b + Substring.nextn ss n 0, stopPos := e }
@[inline]
Equations
@[inline]
Equations
  • Substring.take _fun_discr _fun_discr = match _fun_discr, _fun_discr with | ss@h:{ str := s, startPos := b, stopPos := stopPos }, n => { str := s, startPos := b, stopPos := b + Substring.nextn ss n 0 }
@[inline]
Equations
@[inline]
Equations
  • Substring.atEnd _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := str, startPos := b, stopPos := e }, p => b + p == e
@[inline]
Equations
  • Substring.extract _fun_discr _fun_discr _fun_discr = match _fun_discr, _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, b', e' => if b' e' then { str := "", startPos := 0, stopPos := 0 } else { str := s, startPos := String.Pos.min e (b + b'), stopPos := String.Pos.min e (b + e') }
Equations
@[inline]
def Substring.foldl {α : Type u} (f : αCharα) (init : α) (s : Substring) :
α
Equations
@[inline]
def Substring.foldr {α : Type u} (f : Charαα) (init : α) (s : Substring) :
α
Equations
@[inline]
def Substring.any (s : Substring) (p : CharBool) :
Equations
@[inline]
def Substring.all (s : Substring) (p : CharBool) :
Equations
Equations
@[inline]
Equations
  • Substring.takeWhile _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, p => let e := Substring.takeWhileAux s e p b; { str := s, startPos := b, stopPos := e }
@[inline]
Equations
  • Substring.dropWhile _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, p => let b := Substring.takeWhileAux s e p b; { str := s, startPos := b, stopPos := e }
@[inline]
Equations
@[inline]
Equations
@[inline]
Equations
Equations
def Substring.beq (ss1 : Substring) (ss2 : Substring) :
Equations
@[inline]
def String.nextWhile (s : String) (p : CharBool) (i : String.Pos) :
Equations
@[inline]
def String.nextUntil (s : String) (p : CharBool) (i : String.Pos) :
Equations