Equations
- String.instOfNatPos = { ofNat := { byteIdx := 0 } }
Equations
- String.instLTString = { lt := fun s₁ s₂ => s₁.data < s₂.data }
Equations
- String.decLt s₁ s₂ = List.hasDecidableLt s₁.data s₂.data
Equations
- String.length _fun_discr = match _fun_discr with | { data := s } => List.length s
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.
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
- String.toList s = s.data
O(n) in the runtime, where n is the length of the String
Equations
- String.get _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { data := s }, p => String.utf8GetAux s 0 p
Equations
- String.getOp self idx = String.get self idx
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 }
Equations
- String.modify s i f = String.set s i (f (String.get s i))
Equations
- String.next s p = let c := String.get s p; p + c
Equations
- String.prev _fun_discr _fun_discr = match _fun_discr, _fun_discr 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.endPos s))
Equations
- String.atEnd _fun_discr _fun_discr = match _fun_discr, _fun_discr with | s, p => decide (p.byteIdx ≥ String.utf8ByteSize s)
Equations
- String.posOf s c = String.posOfAux s c (String.endPos s) 0
Equations
- String.revPosOf s c = if (String.endPos s == 0) = true then none else String.revPosOfAux s c (String.prev s (String.endPos s))
Equations
- String.find s p = String.findAux s p (String.endPos s) 0
Equations
- String.revFind s p = if (String.endPos s == 0) = true then none else String.revFindAux s p (String.prev s (String.endPos s))
Equations
- String.Pos.min p₁ p₂ = { byteIdx := Nat.min p₁.byteIdx p₂.byteIdx }
Equations
- String.firstDiffPos a b = let stopPos := String.Pos.min (String.endPos a) (String.endPos b); String.firstDiffPos.loop a b stopPos 0
Returns the first position where the two strings differ.
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
- String.extract.go₁ [] _fun_discr _fun_discr _fun_discr = []
- String.extract.go₁ (c :: cs) _fun_discr _fun_discr _fun_discr = if _fun_discr = _fun_discr then String.extract.go₂ (c :: cs) _fun_discr _fun_discr else String.extract.go₁ cs (_fun_discr + c) _fun_discr _fun_discr
Equations
- String.extract.go₂ [] _fun_discr _fun_discr = []
- String.extract.go₂ (c :: cs) _fun_discr _fun_discr = if _fun_discr = _fun_discr then [] else c :: String.extract.go₂ cs (_fun_discr + c) _fun_discr
Equations
- String.split s p = String.splitAux s p 0 0 []
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 _fun_discr = match _fun_discr with | [] => "" | a :: as => String.intercalate.go a s as
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
Equations
- String.instSizeOfIterator = { sizeOf := fun i => String.utf8ByteSize i.s - i.i.byteIdx }
Equations
- String.Iterator.toString _fun_discr = match _fun_discr with | { s := s, i := i } => s
Equations
- String.Iterator.remainingBytes _fun_discr = match _fun_discr with | { s := s, i := i } => (String.endPos s).byteIdx - i.byteIdx
Equations
- String.Iterator.pos _fun_discr = match _fun_discr with | { s := s, i := i } => i
Equations
- String.Iterator.curr _fun_discr = match _fun_discr with | { s := s, i := i } => String.get s i
Equations
- String.Iterator.next _fun_discr = match _fun_discr with | { s := s, i := i } => { s := s, i := String.next s i }
Equations
- String.Iterator.prev _fun_discr = match _fun_discr with | { s := s, i := i } => { s := s, i := String.prev s i }
Equations
- String.Iterator.atEnd _fun_discr = match _fun_discr with | { s := s, i := i } => decide (i.byteIdx ≥ (String.endPos s).byteIdx)
Equations
- String.Iterator.hasNext _fun_discr = match _fun_discr with | { s := s, i := i } => decide (i.byteIdx < (String.endPos s).byteIdx)
Equations
- String.Iterator.hasPrev _fun_discr = match _fun_discr with | { s := s, i := i } => decide (i.byteIdx > 0)
Equations
- String.Iterator.setCurr _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { s := s, i := i }, c => { s := String.set s i c, i := i }
Equations
- String.Iterator.toEnd _fun_discr = match _fun_discr with | { s := s, i := i } => { s := s, i := String.endPos s }
Equations
- String.Iterator.extract _fun_discr _fun_discr = match _fun_discr, _fun_discr 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
- String.Iterator.forward _fun_discr 0 = _fun_discr
- String.Iterator.forward _fun_discr (Nat.succ n) = String.Iterator.forward (String.Iterator.next _fun_discr) n
Equations
- String.Iterator.remainingToString _fun_discr = match _fun_discr with | { s := s, i := i } => String.extract s i (String.endPos s)
Equations
- String.Iterator.nextn _fun_discr 0 = _fun_discr
- String.Iterator.nextn _fun_discr (Nat.succ n) = String.Iterator.nextn (String.Iterator.next _fun_discr) n
Equations
- String.Iterator.prevn _fun_discr 0 = _fun_discr
- String.Iterator.prevn _fun_discr (Nat.succ n) = String.Iterator.prevn (String.Iterator.prev _fun_discr) n
Equations
- String.offsetOfPos s pos = String.offsetOfPosAux s pos 0 0
Equations
- String.foldlAux f s stopPos i a = String.foldlAux.loop f s stopPos i a
Equations
- String.foldl f init s = String.foldlAux f s (String.endPos s) 0 init
Equations
- String.foldrAux f a s stopPos i = String.foldrAux.loop f a s stopPos i
Equations
- String.foldr f init s = String.foldrAux f init s (String.endPos s) 0
Equations
- String.anyAux s stopPos p i = String.anyAux.loop s stopPos p i
Equations
- String.any s p = String.anyAux s (String.endPos s) p 0
Equations
- String.all s p = !String.any s fun c => !p c
Equations
- String.contains s c = String.any s fun a => a == c
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
Equations
- String.substrEq s1 off1 s2 off2 sz = (decide (off1.byteIdx + sz ≤ (String.endPos s1).byteIdx) && decide (off2.byteIdx + sz ≤ (String.endPos s2).byteIdx) && String.substrEq.loop s1 s2 off1 off2 { byteIdx := off1.byteIdx + sz })
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.
Equations
- String.isPrefixOf p s = String.substrEq p 0 s 0 (String.endPos p).byteIdx
Equations
- String.replace s pattern replacement = String.replace.loop s pattern replacement "" 0 0
Replace all occurrences of pattern
in s
with replacment
.
Equations
- Substring.isEmpty ss = (Substring.bsize ss == 0)
Equations
- Substring.toString _fun_discr = match _fun_discr with | { str := s, startPos := b, stopPos := e } => String.extract s b e
Equations
- Substring.toIterator _fun_discr = match _fun_discr with | { str := s, startPos := b, stopPos := stopPos } => { s := s, i := b }
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.
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.
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
- Substring.nextn _fun_discr 0 _fun_discr = _fun_discr
- Substring.nextn _fun_discr (Nat.succ i) _fun_discr = Substring.nextn _fun_discr i (Substring.next _fun_discr _fun_discr)
Equations
- Substring.prevn _fun_discr 0 _fun_discr = _fun_discr
- Substring.prevn _fun_discr (Nat.succ i) _fun_discr = Substring.prevn _fun_discr i (Substring.prev _fun_discr _fun_discr)
Equations
- Substring.front s = Substring.get s 0
Equations
- Substring.posOf s c = match s with | { str := s, startPos := b, stopPos := e } => { byteIdx := (String.posOfAux s c e b).byteIdx - b.byteIdx }
Return the offset into s
of the first occurence of c
in s
,
or s.bsize
if c
doesn't occur.
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 }
Equations
- Substring.dropRight _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.prevn ss n { byteIdx := Substring.bsize ss } }
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 }
Equations
- Substring.takeRight _fun_discr _fun_discr = match _fun_discr, _fun_discr with | ss@h:{ str := s, startPos := b, stopPos := e }, n => { str := s, startPos := b + Substring.prevn ss n { byteIdx := Substring.bsize ss }, stopPos := e }
Equations
- Substring.atEnd _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := str, startPos := b, stopPos := e }, p => b + p == e
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
- Substring.splitOn s sep = if (sep == "") = true then [s] else Substring.splitOn.loop s sep 0 0 0 []
Equations
- Substring.foldl f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldlAux f s e b init
Equations
- Substring.foldr f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldrAux f init s e b
Equations
- Substring.any s p = match s with | { str := s, startPos := b, stopPos := e } => String.anyAux s e p b
Equations
- Substring.all s p = !Substring.any s fun c => !p c
Equations
- Substring.contains s c = Substring.any s fun a => a == c
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 }
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 }
Equations
- Substring.takeRightWhile _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, p => let b := Substring.takeRightWhileAux s b p e; { str := s, startPos := b, stopPos := e }
Equations
- Substring.dropRightWhile _fun_discr _fun_discr = match _fun_discr, _fun_discr with | { str := s, startPos := b, stopPos := e }, p => let e := Substring.takeRightWhileAux s b p e; { str := s, startPos := b, stopPos := e }
Equations
Equations
Equations
- Substring.trim _fun_discr = match _fun_discr 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
Equations
- String.nextWhile s p i = Substring.takeWhileAux s (String.endPos s) p i
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))