Equations
- String.instOfNatPos = { ofNat := { byteIdx := 0 } }
Equations
- String.instLT = { lt := fun (s₁ s₂ : String) => s₁.data < s₂.data }
Equations
- x.length = match x with | { data := s } => s.length
Instances For
Returns true if p
is a valid UTF-8 position in the string s
, meaning that p ≤ s.endPos
and p
lies on a UTF-8 character boundary. This has an O(1) implementation in the runtime.
Equations
- String.Pos.isValid s p = String.Pos.isValid.go p s.data 0
Instances For
Equations
- String.Pos.isValid.go p [] x = decide (x = p)
- String.Pos.isValid.go p (c :: cs) x = if x = p then true else String.Pos.isValid.go p cs (x + c)
Instances For
Equations
- String.utf8GetAux [] x✝ x = default
- String.utf8GetAux (c :: cs) x✝ x = if x✝ = x then c else String.utf8GetAux cs (x✝ + c) x
Instances For
Return character at position p
. If p
is not a valid position
returns (default : Char)
.
See utf8GetAux
for the reference implementation.
Equations
- s.get p = match s with | { data := s } => String.utf8GetAux s 0 p
Instances For
Equations
- String.utf8GetAux? [] x✝ x = none
- String.utf8GetAux? (c :: cs) x✝ x = if x✝ = x then some c else String.utf8GetAux? cs (x✝ + c) x
Instances For
Equations
- x✝.get? x = match x✝, x with | { data := s }, p => String.utf8GetAux? s 0 p
Instances For
Similar to get
, but produces a panic error message if p
is not a valid String.Pos
.
Equations
- s.get! p = match s with | { data := s } => String.utf8GetAux s 0 p
Instances For
Equations
- String.utf8SetAux c' [] x✝ x = []
- String.utf8SetAux c' (c :: cs) x✝ x = if x✝ = x then c' :: cs else c :: String.utf8SetAux c' cs (x✝ + c) x
Instances For
Equations
- x✝¹.set x✝ x = match x✝¹, x✝, x with | { data := s }, i, c => { data := String.utf8SetAux c s 0 i }
Instances For
Equations
- s.modify i f = s.set i (f (s.get i))
Instances For
Instances For
Equations
- String.utf8PrevAux [] x✝ x = 0
- String.utf8PrevAux (c :: cs) x✝ x = let i' := x✝ + c; if i' = x then x✝ else String.utf8PrevAux cs i' x
Instances For
Equations
- x✝.prev x = match x✝, x with | { data := s }, p => if p = 0 then 0 else String.utf8PrevAux s 0 p
Instances For
Instances For
Similar to get
but runtime does not perform bounds check.
Equations
- s.get' p h = match s, h with | { data := s }, h => String.utf8GetAux s 0 p
Instances For
Similar to next
but runtime does not perform bounds check.
Instances For
Equations
Instances For
Equations
Instances For
Equations
- s.revPosOf c = s.revPosOfAux c s.endPos
Instances For
Equations
Instances For
Equations
Instances For
Equations
- s.revFind p = s.revFindAux p s.endPos
Instances For
Returns the first position where the two strings differ.
Equations
- a.firstDiffPos b = let stopPos := a.endPos.min b.endPos; String.firstDiffPos.loop a b stopPos 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- x✝¹.extract x✝ x = match x✝¹, x✝, x with | { data := s }, b, e => if b.byteIdx ≥ e.byteIdx then "" else { data := String.extract.go₁ s 0 b e }
Instances For
Equations
- String.extract.go₁ [] x✝¹ x✝ x = []
- String.extract.go₁ (c :: cs) x✝¹ x✝ x = if x✝¹ = x✝ then String.extract.go₂ (c :: cs) x✝¹ x else String.extract.go₁ cs (x✝¹ + c) x✝ x
Instances For
Equations
- String.extract.go₂ [] x✝ x = []
- String.extract.go₂ (c :: cs) x✝ x = if x✝ = x then [] else c :: String.extract.go₂ cs (x✝ + c) x
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Auxiliary for splitOn
. Preconditions:
It represents the state where we have currently parsed some split parts into r
(in reverse order),
b
is the beginning of the string / the end of the previous match of sep
, and the first j
bytes
of sep
match the bytes i-j .. i
of s
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Splits a string s
on occurrences of the separator sep
. When sep
is empty, it returns [s]
;
when sep
occurs in overlapping patterns, the first match is taken. There will always be exactly
n+1
elements in the returned list if there were n
nonoverlapping matches of sep
in the string.
The default separator is " "
. The separators are not included in the returned substrings.
"here is some text ".splitOn = ["here", "is", "some", "text", ""]
"here is some text ".splitOn "some" = ["here is ", " text "]
"here is some text ".splitOn "" = ["here is some text "]
"ababacabac".splitOn "aba" = ["", "bac", "c"]
Instances For
Equations
- String.instInhabited = { default := "" }
Equations
- String.instAppend = { append := String.append }
Equations
- s.pushn c n = Nat.repeat (fun (s : String) => s.push c) n s
Instances For
Equations
- String.join l = List.foldl (fun (r s : String) => r ++ s) "" l
Instances For
Equations
- s.intercalate x = match x with | [] => "" | a :: as => String.intercalate.go a s as
Instances For
Equations
- String.intercalate.go acc s (a :: as) = String.intercalate.go (acc ++ s ++ a) s as
- String.intercalate.go acc s [] = acc
Instances For
Iterator over the characters (Char
) of a String
.
Typically created by s.iter
, where s
is a String
.
An iterator is valid if the position i
is valid for the string s
, meaning 0 ≤ i ≤ s.endPos
and i
lies on a UTF8 byte boundary. If i = s.endPos
, the iterator is at the end of the string.
Most operations on iterators return arbitrary values if the iterator is not valid. The functions in
the String.Iterator
API should rule out the creation of invalid iterators, with two exceptions:
Iterator.next iter
is invalid ifiter
is already at the end of the string (iter.atEnd
istrue
), andIterator.forward iter n
/Iterator.nextn iter n
is invalid ifn
is strictly greater than the number of remaining characters.
- s : String
The string the iterator is for.
- i : String.Pos
The current position.
This position is not necessarily valid for the string, for instance if one keeps calling
Iterator.next
whenIterator.atEnd
is true. If the position is not valid, then the current character is(default : Char)
, similar toString.get
on an invalid position.
Instances For
Creates an iterator at the beginning of a string.
Equations
- s.mkIterator = { s := s, i := 0 }
Instances For
Creates an iterator at the beginning of a string.
Equations
Instances For
The size of a string iterator is the number of bytes remaining.
Equations
- String.instSizeOfIterator = { sizeOf := fun (i : String.Iterator) => i.s.utf8ByteSize - i.i.byteIdx }
The string the iterator is for.
Equations
Instances For
Number of bytes remaining in the iterator.
Instances For
The current position.
This position is not necessarily valid for the string, for instance if one keeps calling
Iterator.next
when Iterator.atEnd
is true. If the position is not valid, then the
current character is (default : Char)
, similar to String.get
on an invalid position.
Equations
Instances For
The character at the current position.
On an invalid position, returns (default : Char)
.
Equations
- x.curr = match x with | { s := s, i := i } => s.get i
Instances For
Moves the iterator's position forward by one character, unconditionally.
It is only valid to call this function if the iterator is not at the end of the string, i.e.
Iterator.atEnd
is false
; otherwise, the resulting iterator will be invalid.
Equations
- x.next = match x with | { s := s, i := i } => { s := s, i := s.next i }
Instances For
Decreases the iterator's position.
If the position is zero, this function is the identity.
Equations
- x.prev = match x with | { s := s, i := i } => { s := s, i := s.prev i }
Instances For
True if the iterator is past the string's last character.
Instances For
True if the iterator is not past the string's last character.
Instances For
True if the position is not zero.
Instances For
Replaces the current character in the string.
Does nothing if the iterator is at the end of the string. If the iterator contains the only reference to its string, this function will mutate the string in-place instead of allocating a new one.
Equations
- x✝.setCurr x = match x✝, x with | { s := s, i := i }, c => { s := s.set i c, i := i }
Instances For
Extracts the substring between the positions of two iterators.
Returns the empty string if the iterators are for different strings, or if the position of the first iterator is past the position of the second iterator.
Equations
Instances For
Moves the iterator's position several characters forward.
The resulting iterator is only valid if the number of characters to skip is less than or equal to the number of characters left in the iterator.
Instances For
The remaining characters in an iterator, as a string.
Equations
- x.remainingToString = match x with | { s := s, i := i } => s.extract i s.endPos
Instances For
Moves the iterator's position several characters forward.
The resulting iterator is only valid if the number of characters to skip is less than or equal to the number of characters left in the iterator.
Instances For
Moves the iterator's position several characters back.
If asked to go back more characters than available, stops at the beginning of the string.
Instances For
Equations
Instances For
Equations
- s.offsetOfPos pos = s.offsetOfPosAux pos 0 0
Instances For
Equations
- String.foldlAux f s stopPos i a = if h : i < stopPos then let_fun this := ⋯; String.foldlAux f s stopPos (s.next i) (f a (s.get i)) else a
Instances For
Equations
- String.foldrAux f a s i begPos = if h : begPos < i then let_fun this := ⋯; let i := s.prev i; let a := f (s.get i) a; String.foldrAux f a s i begPos else a
Instances For
Equations
Instances For
Equations
- String.mapAux f i s = if h : s.atEnd i = true then s else let c := f (s.get i); let_fun this := ⋯; let s := s.set i c; String.mapAux f (s.next i) s
Instances For
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
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Replace all occurrences of pattern
in s
with replacement
.
Equations
- s.replace pattern replacement = if h : pattern.endPos.byteIdx = 0 then s else let_fun hPatt := ⋯; String.replace.loop s pattern replacement hPatt "" 0 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- x.toString = match x with | { str := s, startPos := b, stopPos := e } => s.extract b e
Instances For
Equations
- x.toIterator = match x with | { str := s, startPos := b, stopPos := stopPos } => { s := s, i := b }
Instances For
Return the codepoint at the given offset into the substring.
Equations
Instances For
Given an offset of a codepoint into the substring, return the offset there of the next codepoint.
Equations
Instances For
Given an offset of a codepoint into the substring, return the offset there of the previous codepoint.
Equations
Instances For
Instances For
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Substring.foldl f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldlAux f s e b init
Instances For
Equations
- Substring.foldr f init s = match s with | { str := s, startPos := b, stopPos := e } => String.foldrAux f init s e b
Instances For
Equations
- Substring.takeWhileAux s stopPos p i = if h : i < stopPos then if p (s.get i) = true then let_fun this := ⋯; Substring.takeWhileAux s stopPos p (s.next i) else i else i
Instances For
Equations
- x✝.takeWhile 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 }
Instances For
Equations
- x✝.dropWhile 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 }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- x✝.takeRightWhile 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 }
Instances For
Equations
- x✝.dropRightWhile 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 }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- s.trimRight = s.toSubstring.trimRight.toString
Instances For
Equations
- s.trimLeft = s.toSubstring.trimLeft.toString
Instances For
Equations
- s.trim = s.toSubstring.trim.toString
Instances For
Instances For
Equations
- s.toUpper = String.map Char.toUpper s
Instances For
Equations
- s.toLower = String.map Char.toLower s
Instances For
Equations
- s.capitalize = s.set 0 (s.get 0).toUpper
Instances For
Equations
- s.decapitalize = s.set 0 (s.get 0).toLower