Equations
- String.instLTString = { lt := fun s₁ s₂ => s₁.data < s₂.data }
@[extern lean_string_dec_lt]
Equations
- String.decLt s₁ s₂ = List.hasDecidableLt s₁.data s₂.data
@[extern lean_string_length]
Equations
- String.length x = match x with | { data := s } => List.length s
@[extern lean_string_push]
Equations
- String.push x x = match x, x with | { data := s }, c => { data := s ++ [c] }
@[extern lean_string_append]
Equations
- String.append x x = match x, x with | { data := a }, { data := b } => { data := a ++ b }
@[extern lean_string_utf8_get]
Equations
- String.get x x = match x, x with | { data := s }, p => String.utf8GetAux s 0 p
Equations
- String.getOp self idx = String.get self idx
@[extern lean_string_utf8_set]
Equations
- String.set x x x = match x, x, x with | { data := s }, i, c => { data := String.utf8SetAux c s 0 i }
Equations
- String.modify s i f = String.set s i (f (String.get s i))
@[extern lean_string_utf8_next]
Equations
- String.next s p = let c := String.get s p; p + String.csize c
@[extern lean_string_utf8_prev]
Equations
- String.prev x x = match x, x with | { data := s }, p => if p = 0 then 0 else String.utf8PrevAux s 0 p
Equations
- String.back s = String.get s (String.prev s (String.bsize s))
@[extern lean_string_utf8_at_end]
Equations
- String.atEnd x x = match x, x with | s, p => decide (p ≥ String.utf8ByteSize s)
@[inline]
Equations
- String.posOf s c = String.posOfAux s c (String.bsize s) 0
Equations
- String.revPosOf s c = if (String.bsize s == 0) = true then none else String.revPosOfAux s c (String.prev s (String.bsize s))
partial def
String.findAux
(s : String)
(p : Char → Bool)
(stopPos : String.Pos)
(pos : String.Pos)
:
@[inline]
Equations
- String.find s p = String.findAux s p (String.bsize s) 0
Equations
- String.revFind s p = if (String.bsize s == 0) = true then none else String.revFindAux s p (String.prev s (String.bsize s))
Equations
- String.firstDiffPos a b = let stopPos := Nat.min (String.bsize a) (String.bsize b); (fun loop => loop 0) (String.firstDiffPos.loop a b stopPos)
@[extern lean_string_utf8_extract]
Equations
- String.extract x x x = match x, x, x with | { data := s }, b, e => if b ≥ e then { data := [] } else { data := String.utf8ExtractAux₁ s 0 b e }
@[specialize]
partial def
String.splitAux
(s : String)
(p : Char → Bool)
(b : String.Pos)
(i : String.Pos)
(r : List String)
:
@[specialize]
Equations
- String.split s p = String.splitAux s p 0 0 []
partial def
String.splitOnAux
(s : String)
(sep : String)
(b : String.Pos)
(i : String.Pos)
(j : String.Pos)
(r : List String)
:
Equations
- String.splitOn s sep = if (sep == "") = true then [s] else String.splitOnAux s sep 0 0 0 []
Equations
- String.instInhabitedString = { default := "" }
Equations
- String.instAppendString = { append := String.append }
Equations
- String.pushn s c n = Nat.repeat (fun s => String.push s c) n s
Equations
- String.join l = List.foldl (fun r s => r ++ s) "" l
Equations
- String.intercalate s x = (fun go => match x with | [] => "" | a :: as => go a s as) String.intercalate.go
Equations
- String.intercalate.go acc s (a :: as) = String.intercalate.go (acc ++ s ++ a) s as
- String.intercalate.go acc s [] = acc
Equations
Equations
- String.mkIterator s = { s := s, i := 0 }
Equations
- String.Iterator.toString x = match x with | { s := s, i := x } => s
Equations
- String.Iterator.remainingBytes x = match x with | { s := s, i := i } => String.bsize s - i
Equations
- String.Iterator.pos x = match x with | { s := s, i := i } => i
Equations
- String.Iterator.curr x = match x with | { s := s, i := i } => String.get s i
Equations
- String.Iterator.next x = match x with | { s := s, i := i } => { s := s, i := String.next s i }
Equations
- String.Iterator.prev x = match x with | { s := s, i := i } => { s := s, i := String.prev s i }
Equations
- String.Iterator.hasNext x = match x with | { s := s, i := i } => decide (i < String.utf8ByteSize s)
Equations
- String.Iterator.hasPrev x = match x with | { s := s, i := i } => decide (i > 0)
Equations
- String.Iterator.setCurr x x = match x, x with | { s := s, i := i }, c => { s := String.set s i c, i := i }
Equations
- String.Iterator.toEnd x = match x with | { s := s, i := x } => { s := s, i := String.bsize s }
Equations
- String.Iterator.extract x x = match x, x with | { s := s₁, i := b }, { s := s₂, i := e } => if (decide (s₁ ≠ s₂) || decide (b > e)) = true then "" else String.extract s₁ b e
Equations
Equations
- String.Iterator.remainingToString x = match x with | { s := s, i := i } => String.extract s i (String.bsize s)
Equations
- String.Iterator.nextn x 0 = x
- String.Iterator.nextn x (Nat.succ n) = String.Iterator.nextn (String.Iterator.next x) n
Equations
- String.Iterator.prevn x 0 = x
- String.Iterator.prevn x (Nat.succ n) = String.Iterator.prevn (String.Iterator.prev x) n
Equations
- String.offsetOfPos s pos = String.offsetOfPosAux s pos 0 0
@[specialize]
def
String.foldlAux
{α : Type u}
(f : α → Char → α)
(s : String)
(stopPos : String.Pos)
(i : String.Pos)
(a : α)
:
α
Equations
- String.foldlAux f s stopPos i a = (fun loop => loop i a) (String.foldlAux.loop f s stopPos)
partial def
String.foldlAux.loop
{α : Type u}
(f : α → Char → α)
(s : String)
(stopPos : String.Pos)
(i : String.Pos)
(a : α)
:
α
@[inline]
Equations
- String.foldl f init s = String.foldlAux f s (String.bsize s) 0 init
@[specialize]
def
String.foldrAux
{α : Type u}
(f : Char → α → α)
(a : α)
(s : String)
(stopPos : String.Pos)
(i : String.Pos)
:
α
Equations
- String.foldrAux f a s stopPos i = (fun loop => loop i) (String.foldrAux.loop f a s stopPos)
partial def
String.foldrAux.loop
{α : Type u}
(f : Char → α → α)
(a : α)
(s : String)
(stopPos : String.Pos)
(i : String.Pos)
:
α
@[inline]
Equations
- String.foldr f init s = String.foldrAux f init s (String.bsize s) 0
@[specialize]
Equations
- String.anyAux s stopPos p i = (fun loop => loop i) (String.anyAux.loop s stopPos p)
partial def
String.anyAux.loop
(s : String)
(stopPos : String.Pos)
(p : Char → Bool)
(i : String.Pos)
:
@[inline]
Equations
- String.any s p = String.anyAux s (String.bsize s) p 0
@[inline]
Equations
- String.all s p = !String.any s fun c => !p c
Equations
- String.contains s c = String.any s fun a => a == c
@[specialize]
@[inline]
Equations
- String.map f s = String.mapAux f 0 s
Equations
- String.isNat s = String.all s fun c => Char.isDigit c
Equations
- String.toNat? s = if String.isNat s = true then some (String.foldl (fun n c => n * 10 + (Char.toNat c - Char.toNat (Char.ofNat 48))) 0 s) else none
def
String.substrEq
(s1 : String)
(off1 : String.Pos)
(s2 : String)
(off2 : String.Pos)
(sz : Nat)
:
Equations
- String.substrEq s1 off1 s2 off2 sz = (fun loop => decide (off1 + sz ≤ String.bsize s1) && decide (off2 + sz ≤ String.bsize s2) && loop off1 off2 (off1 + sz)) (String.substrEq.loop s1 s2)
partial def
String.substrEq.loop
(s1 : String)
(s2 : String)
(off1 : String.Pos)
(off2 : String.Pos)
(stop1 : String.Pos)
:
Equations
- String.isPrefixOf p s = String.substrEq p 0 s 0 (String.bsize p)
Equations
- String.replace s pattern replacement = (fun loop => loop "" 0 0) (String.replace.loop s pattern replacement)
partial def
String.replace.loop
(s : String)
(pattern : String)
(replacement : String)
(acc : String)
(accStop : String.Pos)
(pos : String.Pos)
:
@[inline]
Equations
- Substring.isEmpty ss = (Substring.bsize ss == 0)
@[inline]
Equations
- Substring.toString x = match x with | { str := s, startPos := b, stopPos := e } => String.extract s b e
@[inline]
Equations
- Substring.toIterator x = match x with | { str := s, startPos := b, stopPos := x } => { s := s, i := b }
@[inline]
Equations
- Substring.get x x = match x, x with | { str := s, startPos := b, stopPos := x }, p => String.get s (b + p)
@[inline]
Equations
- Substring.next x x = match x, x with | { str := s, startPos := b, stopPos := e }, p => let absP := b + p; if absP = e then p else String.next s absP - b
@[inline]
Equations
- Substring.prev x x = match x, x with | { str := s, startPos := b, stopPos := x }, p => let absP := b + p; if absP = b then p else String.prev s absP - b
Equations
- Substring.nextn x 0 x = x
- Substring.nextn x (Nat.succ i) x = Substring.nextn x i (Substring.next x x)
Equations
- Substring.prevn x 0 x = x
- Substring.prevn x (Nat.succ i) x = Substring.prevn x i (Substring.prev x x)
@[inline]
Equations
- Substring.front s = Substring.get s 0
@[inline]
Equations
- Substring.posOf s c = match s with | { str := s, startPos := b, stopPos := e } => String.posOfAux s c e b - b
@[inline]
Equations
- Substring.drop x x = match x, x with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b + Substring.nextn ss n 0, stopPos := e }
@[inline]
Equations
- Substring.dropRight x x = match x, x with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b, stopPos := b + Substring.prevn ss n (Substring.bsize ss) }
@[inline]
Equations
- Substring.take x x = match x, x with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b, stopPos := b + Substring.nextn ss n 0 }
@[inline]
Equations
- Substring.takeRight x x = match x, x with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b + Substring.prevn ss n (Substring.bsize ss), stopPos := e }
@[inline]
Equations
- Substring.atEnd x x = match x, x with | { str := s, startPos := b, stopPos := e }, p => b + p == e
@[inline]
Equations
- Substring.splitOn s sep = if (sep == "") = true then [s] else (fun loop => loop 0 0 0 []) (Substring.splitOn.loop s sep)
partial def
Substring.splitOn.loop
(s : Substring)
(sep : optParam String " ")
(b : String.Pos)
(i : String.Pos)
(j : String.Pos)
(r : List Substring)
:
@[inline]
Equations
- Substring.foldl f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldlAux f s e b init
@[inline]
Equations
- Substring.foldr f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldrAux f init s e b
@[inline]
Equations
- Substring.any s p = match s with | { str := s, startPos := b, stopPos := e } => String.anyAux s e p b
@[inline]
Equations
- Substring.all s p = !Substring.any s fun c => !p c
Equations
- Substring.contains s c = Substring.any s fun a => a == c
@[inline]
Equations
- Substring.takeWhile x x = match x, x 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 x x = match x, x with | { str := s, startPos := b, stopPos := e }, p => let b := Substring.takeWhileAux s e p b; { str := s, startPos := b, stopPos := e }
@[inline]
Equations
- Substring.takeRightWhile x x = match x, x with | { str := s, startPos := b, stopPos := e }, p => let b := Substring.takeRightWhileAux s b p e; { str := s, startPos := b, stopPos := e }
@[inline]
Equations
- Substring.dropRightWhile x x = match x, x with | { str := s, startPos := b, stopPos := e }, p => let e := Substring.takeRightWhileAux s b p e; { str := s, startPos := b, stopPos := e }
@[inline]
Equations
@[inline]
Equations
@[inline]
Equations
- Substring.trim x = match x with | { str := s, startPos := b, stopPos := e } => let b := Substring.takeWhileAux s e Char.isWhitespace b; let e := Substring.takeRightWhileAux s b Char.isWhitespace e; { str := s, startPos := b, stopPos := e }
Equations
- Substring.isNat s = Substring.all s fun c => Char.isDigit c
Equations
- Substring.toNat? s = if Substring.isNat s = true then some (Substring.foldl (fun n c => n * 10 + (Char.toNat c - Char.toNat (Char.ofNat 48))) 0 s) else none
Equations
- Substring.beq ss1 ss2 = (Substring.bsize ss1 == Substring.bsize ss2 && String.substrEq ss1.str ss1.startPos ss2.str ss2.startPos (Substring.bsize ss1))
Equations
- Substring.hasBeq = { beq := Substring.beq }
Equations
- String.drop s n = Substring.toString (Substring.drop (String.toSubstring s) n)
Equations
Equations
- String.take s n = Substring.toString (Substring.take (String.toSubstring s) n)
Equations
Equations
Equations
Equations
Equations
Equations
- String.startsWith s pre = (Substring.take (String.toSubstring s) (String.length pre) == String.toSubstring pre)
Equations
- String.endsWith s post = (Substring.takeRight (String.toSubstring s) (String.length post) == String.toSubstring post)
Equations
Equations
Equations
@[inline]
Equations
- String.nextWhile s p i = Substring.takeWhileAux s (String.bsize s) p i
@[inline]
Equations
- String.nextUntil s p i = String.nextWhile s (fun c => !p c) i
Equations
Equations
Equations
- String.capitalize s = String.set s 0 (Char.toUpper (String.get s 0))
Equations
- String.decapitalize s = String.set s 0 (Char.toLower (String.get s 0))