Checks whether a slice is empty.
Empty slices have utf8ByteSize 0.
Examples:
Equations
- s.isEmpty = (s.utf8ByteSize == 0)
Instances For
Checks whether s1 and s2 represent the same string, even if they are slices of
different base strings or different slices within the same string.
The implementation is an efficient equivalent of s1.copy == s2.copy
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- String.Slice.instBEq = { beq := String.Slice.beq }
Equations
- String.Slice.instHashable = { hash := String.Slice.hash }
Equations
- String.Slice.instLT = { lt := fun (x y : String.Slice) => x.copy < y.copy }
Equations
- x.instDecidableLt y = inferInstanceAs (Decidable (x.copy < y.copy))
Equations
- String.Slice.instOrd = { compare := fun (x y : String.Slice) => compareOfLessAndBEq x y }
Equations
- String.Slice.instLE = { le := fun (x y : String.Slice) => ¬x < y }
Equations
- x.instDecidableLE y = inferInstanceAs (Decidable ¬x < y)
Checks whether the slice (s) begins with the pattern (pat).
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.startsWith "red" = true"red green blue".toSlice.startsWith "green" = false"red green blue".toSlice.startsWith "" = true"red green blue".toSlice.startsWith 'r' = true"red green blue".toSlice.startsWith Char.isLower = true
Equations
Instances For
- operating {σ : Slice → Type} {ρ : Type} [Pattern.ToForwardSearcher ρ σ] (s : Slice) (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : SplitIterator ρ
- atEnd {σ : Slice → Type} {ρ : Type} [Pattern.ToForwardSearcher ρ σ] : SplitIterator ρ
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Splits a slice at each subslice that matches the pattern pat.
The subslices that matched the pattern are not included in any of the resulting subslices. If multiple subslices in a row match the pattern, the resulting list will contain empty strings.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.split Char.isWhitespace).allowNontermination.toList == ["coffee".toSlice, "tea".toSlice, "water".toSlice]("coffee tea water".toSlice.split ' ').allowNontermination.toList == ["coffee".toSlice, "tea".toSlice, "water".toSlice]("coffee tea water".toSlice.split " tea ").allowNontermination.toList == ["coffee".toSlice, "water".toSlice]("ababababa".toSlice.split "aba").allowNontermination.toList == ["coffee".toSlice, "water".toSlice]("baaab".toSlice.split "aa").allowNontermination.toList == ["b".toSlice, "ab".toSlice]
Equations
- s.split pat = { internalState := String.Slice.SplitIterator.operating s s.startPos (String.Slice.Pattern.ToForwardSearcher.toSearcher s pat) }
Instances For
- operating {σ : Slice → Type} {ρ : Type} [Pattern.ToForwardSearcher ρ σ] (s : Slice) (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : SplitInclusiveIterator ρ
- atEnd {σ : Slice → Type} {ρ : Type} [Pattern.ToForwardSearcher ρ σ] : SplitInclusiveIterator ρ
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Splits a slice at each subslice that matches the pattern pat. Unlike split the
matched subslices are included at the end of each subslice.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.splitInclusive Char.isWhitespace).allowNontermination.toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".toSlice.splitInclusive ' ').allowNontermination.toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".toSlice.splitInclusive " tea ").allowNontermination.toList == ["coffee tea ".toSlice, "water".toSlice]("baaab".toSlice.splitInclusive "aa").allowNontermination.toList == ["baa".toSlice, "ab".toSlice]
Equations
- s.splitInclusive pat = { internalState := String.Slice.SplitInclusiveIterator.operating s s.startPos (String.Slice.Pattern.ToForwardSearcher.toSearcher s pat) }
Instances For
If pat matches a prefix of s, returns the remainder. Returns none otherwise.
Use String.Slice.dropPrefix to return the slice
unchanged when pat does not match a prefix.
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.dropPrefix? "red " == some "green blue".toSlice"red green blue".toSlice.dropPrefix? "reed " == none"red green blue".toSlice.dropPrefix? 'r' == some "ed green blue".toSlice"red green blue".toSlice.dropPrefix? Char.isLower == some "ed green blue".toSlice
Equations
Instances For
If pat matches a prefix of s, returns the remainder. Returns s unmodified
otherwise.
Use String.Slice.dropPrefix? to return none when pat does not match a prefix.
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.dropPrefix "red " == "green blue".toSlice"red green blue".toSlice.dropPrefix "reed " == "red green blue".toSlice"red green blue".toSlice.dropPrefix 'r' == "ed green blue".toSlice"red green blue".toSlice.dropPrefix Char.isLower == "ed green blue".toSlice
Equations
- s.dropPrefix pat = (s.dropPrefix? pat).getD s
Instances For
Removes the specified number of characters (Unicode code points) from the start of the slice.
If n is greater than the amount of characters in s, returns an empty slice.
Examples:
"red green blue".toSlice.drop 4 == "green blue".toSlice"red green blue".toSlice.drop 10 == "blue".toSlice"red green blue".toSlice.drop 50 == "".toSlice
Equations
- s.drop n = s.replaceStart (s.startPos.nextn n)
Instances For
Creates a new slice that contains the longest prefix of s for which pat matched
(potentially repeatedly).
Examples:
"red green blue".toSlice.dropWhile Char.isLower == " green blue".toSlice"red green blue".toSlice.dropWhile 'r' == "ed green blue".toSlice"red red green blue".toSlice.dropWhile "red " == "green blue".toSlice"red green blue".toSlice.dropWhile (fun (_ : Char) => true) == "".toSlice
Equations
- s.dropWhile pat = String.Slice.dropWhile.go✝ pat s
Instances For
Removes leading whitespace from a slice by moving its start position to the first non-whitespace character, or to its end position if there is no non-whitespace character.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".toSlice.trimAsciiStart == "abc".toSlice" abc".toSlice.trimAsciiStart == "abc".toSlice"abc \t ".toSlice.trimAsciiStart == "abc \t ".toSlice" abc ".toSlice.trimAsciiStart == "abc ".toSlice"abc\ndef\n".toSlice.trimAsciiStart == "abc\ndef\n".toSlice
Equations
Instances For
Creates a new slice that contains the first n characters (Unicode code points) of s.
If n is greater than the amount of characters in s, returns s.
Examples:
"red green blue".toSlice.take 3 == "red".toSlice"red green blue".toSlice.take 1 == "r".toSlice"red green blue".toSlice.take 0 == "".toSlice"red green blue".toSlice.take 100 == "red green blue".toSlice
Equations
- s.take n = s.replaceEnd (s.startPos.nextn n)
Instances For
Creates a new slice that contains the longest prefix of s for which pat matched
(potentially repeatedly).
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.takeWhile Char.isLower == "red".toSlice"red green blue".toSlice.takeWhile 'r' == "r".toSlice"red red green blue".toSlice.takeWhile "red " == "red red ".toSlice"red green blue".toSlice.takeWhile (fun (_ : Char) => true) == "red green blue".toSlice
Equations
- s.takeWhile pat = String.Slice.takeWhile.go✝ s pat s.startPos
Instances For
Finds the position of the first match of the pattern pat in a slice true. If there
is no match none is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.find? Char.isWhitespace).map (·.get!) == some ' '"tea".toSlice.find? (fun (c : Char) => c == 'X') == none("coffee tea water".toSlice.find? "tea").map (·.get!) == some 't'
Equations
Instances For
Checks whether a slice has a match of the pattern pat anywhere.
This function is generic over all currently supported patterns.
Examples:
"coffee tea water".toSlice.contains Char.isWhitespace = true"tea".toSlice.contains (fun (c : Char) => c == 'X') = false"coffee tea water".toSlice.contains "tea" = true
Equations
Instances For
Checks whether a slice only consists of matches of the pattern pat anywhere.
Short-circuits at the first pattern mis-match.
This function is generic over all currently supported patterns.
Examples:
"brown".toSlice.all Char.isLower = true"brown and orange".toSlice.all Char.isLower = false"aaaaaa".toSlice.all 'a' = true"aaaaaa".toSlice.all "aa" = true
Instances For
Checks whether the slice (s) ends with the pattern (pat).
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.endsWith "blue" = true"red green blue".toSlice.endsWith "green" = false"red green blue".toSlice.endsWith "" = true"red green blue".toSlice.endsWith 'e' = true"red green blue".toSlice.endsWith Char.isLower = true
Equations
- s.endsWith pat = String.Slice.Pattern.BackwardPattern.endsWith s pat
Instances For
- operating {σ : Slice → Type} {ρ : Type} [Pattern.ToBackwardSearcher ρ σ] (s : Slice) (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : RevSplitIterator ρ
- atEnd {σ : Slice → Type} {ρ : Type} [Pattern.ToBackwardSearcher ρ σ] : RevSplitIterator ρ
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Splits a slice at each subslice that matches the pattern pat, starting from the end of the
slice and traversing towards the start.
The subslices that matched the pattern are not included in any of the resulting subslices. If multiple subslices in a row match the pattern, the resulting list will contain empty slices.
This function is generic over all currently supported patterns except
String/String.Slice.
Examples:
("coffee tea water".toSlice.revSplit Char.isWhitespace).allowNontermination.toList == ["water".toSlice, "tea".toSlice, "coffee".toSlice]("coffee tea water".toSlice.revSplit ' ').allowNontermination.toList == ["water".toSlice, "tea".toSlice, "coffee".toSlice]
Equations
- s.revSplit pat = { internalState := String.Slice.RevSplitIterator.operating s s.endPos (String.Slice.Pattern.ToBackwardSearcher.toSearcher s pat) }
Instances For
If pat matches a suffix of s, returns the remainder. Returns none otherwise.
Use String.Slice.dropSuffix to return the slice
unchanged when pat does not match a prefix.
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.dropSuffix? " blue" == some "red green".toSlice"red green blue".toSlice.dropSuffix? "bluu " == none"red green blue".toSlice.dropSuffix? 'e' == some "red green blu".toSlice"red green blue".toSlice.dropSuffix? Char.isLower == some "red green blu".toSlice
Equations
- s.dropSuffix? pat = Option.map s.replaceEnd (String.Slice.Pattern.BackwardPattern.dropSuffix? s pat)
Instances For
If pat matches a suffix of s, returns the remainder. Returns s unmodified
otherwise.
Use String.Slice.dropSuffix? to return none when pat does not match a
prefix.
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.dropSuffix " blue" == "red green".toSlice"red green blue".toSlice.dropSuffix "bluu " == "red green blue".toSlice"red green blue".toSlice.dropSuffix 'e' == "red green blu".toSlice"red green blue".toSlice.dropSuffix Char.isLower == "red green blu".toSlice
Equations
- s.dropSuffix pat = (s.dropSuffix? pat).getD s
Instances For
Removes the specified number of characters (Unicode code points) from the end of the slice.
If n is greater than the amount of characters in s, returns an empty slice.
Examples:
"red green blue".toSlice.dropEnd 5 == "red green".toSlice"red green blue".toSlice.dropEnd 11 == "red".toSlice"red green blue".toSlice.dropEnd 50 == "".toSlice
Equations
- s.dropEnd n = s.replaceEnd (s.endPos.prevn n)
Instances For
Creates a new slice that contains the longest suffix of s for which pat matched
(potentially repeatedly).
Examples:
"red green blue".toSlice.dropEndWhile Char.isLower == "red green ".toSlice"red green blue".toSlice.dropEndWhile 'e' == "red green blu".toSlice"red green blue".toSlice.dropEndWhile (fun (_ : Char) => true) == "".toSlice
Equations
- s.dropEndWhile pat = String.Slice.dropEndWhile.go✝ pat s
Instances For
Removes trailing whitespace from a slice by moving its start position to the first non-whitespace character, or to its end position if there is no non-whitespace character.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".toSlice.trimAsciiEnd == "abc".toSlice" abc".toSlice.trimAsciiEnd == " abc".toSlice"abc \t ".toSlice.trimAsciiEnd == "abc".toSlice" abc ".toSlice.trimAsciiEnd == " abc".toSlice"abc\ndef\n".toSlice.trimAsciiEnd == "abc\ndef".toSlice
Equations
Instances For
Creates a new slice that contains the last n characters (Unicode code points) of s.
If n is greater than the amount of characters in s, returns s.
Examples:
"red green blue".toSlice.takeEnd 4 == "blue".toSlice"red green blue".toSlice.takeEnd 1 == "e".toSlice"red green blue".toSlice.takeEnd 0 == "".toSlice"red green blue".toSlice.takeEnd 100 == "red green blue".toSlice
Equations
- s.takeEnd n = s.replaceStart (s.endPos.prevn n)
Instances For
Creates a new slice that contains the suffix prefix of s for which pat matched
(potentially repeatedly).
This function is generic over all currently supported patterns.
Examples:
"red green blue".toSlice.takeEndWhile Char.isLower == "blue".toSlice"red green blue".toSlice.takeEndWhile 'e' == "e".toSlice"red green blue".toSlice.takeEndWhile (fun (_ : Char) => true) == "red green blue".toSlice
Equations
- s.takeEndWhile pat = String.Slice.takeEndWhile.go✝ s pat s.endPos
Instances For
Finds the position of the first match of the pattern pat in a slice true, starting
from the end of the slice and traversing towards the start. If there is no match none is
returned.
This function is generic over all currently supported patterns except
String/String.Slice.
Examples:
("coffee tea water".toSlice.find? Char.isWhitespace).map (·.get!) == some ' '"tea".toSlice.find? (fun (c : Char) => c == 'X') == none("coffee tea water".toSlice.find? "tea").map (·.get!) == some 't'
Equations
Instances For
Removes leading and trailing whitespace from a slice.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
"abc".toSlice.trimAscii == "abc".toSlice" abc".toSlice.trimAscii == "abc".toSlice"abc \t ".toSlice.trimAscii == "abc".toSlice" abc ".toSlice.trimAscii == "abc".toSlice"abc\ndef\n".toSlice.trimAscii == "abc\ndef".toSlice
Equations
Instances For
Checks whether s1 == s2 if ASCII upper/lowercase are ignored.
Equations
- s1.eqIgnoreAsciiCase s2 = (s1.utf8ByteSize == s2.utf8ByteSize && String.Slice.eqIgnoreAsciiCase.go✝ s1 s1.startPos.offset s2 s2.startPos.offset)
Instances For
Equations
Equations
- String.Slice.instInhabitedPosIterator.default = { currPos := default }
Instances For
Creates an iterator over all valid positions within {name}s.
Examples
- {lean}
("abc".toSlice.positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', 'c'] - {lean}
("abc".toSlice.positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2] - {lean}
("ab∀c".toSlice.positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', '∀', 'c'] - {lean}
("ab∀c".toSlice.positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2, 5]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Creates an iterator over all characters (Unicode code points) in s.
Examples:
"abc".toSlice.chars.toList = ['a', 'b', 'c']"ab∀c".toSlice.chars.toList = ['a', 'b', '∀', 'c']
Equations
Instances For
Equations
- String.Slice.instInhabitedRevPosIterator.default = { currPos := default }
Instances For
Equations
Creates an iterator over all valid positions within {name}s, starting from the last valid
position and iterating towards the first one.
Examples
- {lean}
("abc".toSlice.revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', 'b', 'a'] - {lean}
("abc".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [2, 1, 0] - {lean}
("ab∀c".toSlice.revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', '∀', 'b', 'a'] - {lean}
("ab∀c".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [5, 2, 1, 0]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Creates an iterator over all characters (Unicode code points) in s, starting from the end
of the slice and iterating towards the start.
Example:
"abc".toSlice.revChars.toList = ['c', 'b', 'a']"ab∀c".toSlice.revChars.toList = ['c', '∀', 'b', 'a']
Equations
Instances For
Instances For
Creates an iterator over all bytes in {name}s.
Examples:
- {lean}
"abc".toSlice.bytes.toList = [97, 98, 99] - {lean}
"ab∀c".toSlice.bytes.toList = [97, 98, 226, 136, 128, 99]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Creates an iterator over all bytes in {name}s, starting from the last one and iterating towards
the first one.
Examples:
- {lean}
"abc".toSlice.revBytes.toList = [99, 98, 97] - {lean}
"ab∀c".toSlice.revBytes.toList = [99, 128, 136, 226, 98, 97]
Instances For
Equations
- String.Slice.instInhabitedRevByteIterator = { default := let s := default; { s := s, offset := s.endPos.offset, hinv := String.Slice.instInhabitedRevByteIterator._proof_1 } }
Equations
- One or more equations did not get rendered due to their size.
Equations
- String.Slice.lines.lineMap s = match s.dropSuffix? '\n' with | some s => match s.dropSuffix? '\x0d' with | some s => s | x => s | x => s
Instances For
Creates an iterator over all lines in s with the line ending characters \r\n or \n being
stripped.
Examples:
"foo\r\nbar\n\nbaz\n".toSlice.lines.allowNontermination.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz".toSlice.lines.allowNontermination.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz\r".toSlice.lines.allowNontermination.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz\r".toSlice]
Equations
Instances For
Folds a function over a slice from the start, accumulating a value starting with init. The
accumulated value is combined with each character in order, using f.
Examples:
"coffee tea water".toSlice.foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 2"coffee tea and water".toSlice.foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 3"coffee tea water".toSlice.foldl (·.push ·) "" = "coffee tea water"
Equations
- String.Slice.foldl f init s = Std.Iterators.Iter.fold f init s.chars
Instances For
Folds a function over a slice from the end, accumulating a value starting with init. The
accumulated value is combined with each character in reverse order, using f.
Examples:
"coffee tea water".toSlice.foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 2"coffee tea and water".toSlice.foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 3"coffee tea water".toSlice.foldr (fun c s => s.push c) "" = "retaw aet eeffoc"
Equations
- String.Slice.foldr f init s = Std.Iterators.Iter.fold (flip f) init s.revChars
Instances For
Checks whether the slice can be interpreted as the decimal representation of a natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use toNat? or
toNat! to convert such a slice to a natural number.
Examples:
"".toSlice.isNat = false"0".toSlice.isNat = true"5".toSlice.isNat = true"05".toSlice.isNat = true"587".toSlice.isNat = true"-587".toSlice.isNat = false" 5".toSlice.isNat = false"2+3".toSlice.isNat = false"0xff".toSlice.isNat = false
Instances For
Interprets a slice as the decimal representation of a natural number, returning it. Returns
none if the slice does not contain a decimal natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use isNat to check whether toNat? would return some.
toNat! is an alternative that panics instead of
returning none when the slice is not a natural number.
Examples:
"".toSlice.toNat? = none"0".toSlice.toNat? = some 0"5".toSlice.toNat? = some 5"587".toSlice.toNat? = some 587"-587".toSlice.toNat? = none" 5".toSlice.toNat? = none"2+3".toSlice.toNat? = none"0xff".toSlice.toNat? = none
Equations
Instances For
Interprets a slice as the decimal representation of a natural number, returning it. Panics if the slice does not contain a decimal natural number.
A slice can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use isNat to check whether toNat! would return a value. toNat? is a safer
alternative that returns none instead of panicking when the string is not a natural number.
Examples:
Equations
- One or more equations did not get rendered due to their size.