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} {pat : ρ} {s : Slice} [Pattern.ToForwardSearcher pat σ] (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : SplitIterator pat s
- atEnd {σ : Slice → Type} {ρ : Type} {pat : ρ} {s : Slice} [Pattern.ToForwardSearcher pat σ] : SplitIterator pat s
Instances For
Equations
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 subslices.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.splitToSubslice Char.isWhitespace).toStringList == ["coffee", "tea", "water"]("coffee tea water".toSlice.splitToSubslice ' ').toStringList == ["coffee", "tea", "water"]("coffee tea water".toSlice.splitToSubslice " tea ").toStringList == ["coffee", "water"]("ababababa".toSlice.splitToSubslice "aba").toStringList == ["", "b", "ba"]("baaab".toSlice.splitToSubslice "aa").toStringList == ["b", "ab"]
Equations
- s.splitToSubslice pat = { internalState := String.Slice.SplitIterator.operating s.startPos (String.Slice.Pattern.ToForwardSearcher.toSearcher pat s) }
Instances For
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 slices.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.split Char.isWhitespace).toStringList == ["coffee", "tea", "water"]("coffee tea water".toSlice.split ' ').toStringList == ["coffee", "tea", "water"]("coffee tea water".toSlice.split " tea ").toStringList == ["coffee", "water"]("ababababa".toSlice.split "aba").toStringList == ["", "b", "ba"]("baaab".toSlice.split "aa").toStringList == ["b", "ab"]
Equations
- s.split pat = Std.Iter.map String.Slice.Subslice.toSlice (s.splitToSubslice pat)
Instances For
- operating {σ : Slice → Type} {ρ : Type} {pat : ρ} {s : Slice} [Pattern.ToForwardSearcher pat σ] (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : SplitInclusiveIterator pat s
- atEnd {σ : Slice → Type} {ρ : Type} {pat : ρ} {s : Slice} [Pattern.ToForwardSearcher pat σ] : SplitInclusiveIterator pat s
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).toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".toSlice.splitInclusive ' ').toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".toSlice.splitInclusive " tea ").toList == ["coffee tea ".toSlice, "water".toSlice]("baaab".toSlice.splitInclusive "aa").toList == ["baa".toSlice, "ab".toSlice]
Equations
- s.splitInclusive pat = { internalState := String.Slice.SplitInclusiveIterator.operating s.startPos (String.Slice.Pattern.ToForwardSearcher.toSearcher pat s) }
Instances For
If pat matches a prefix of s, returns the position at the start of the remainder.
Returns none otherwise.
This function is generic over all currently supported patterns.
Equations
Instances For
If pat matches a prefix at pos, returns the position after the end of the match.
Returns none otherwise.
This function is generic over all currently supported patterns.
Equations
- pos.skip? pat = Option.map String.Slice.Pos.ofSliceFrom ((s.sliceFrom pos).skipPrefix? 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
- s.dropPrefix? pat = Option.map s.sliceFrom (s.skipPrefix? pat)
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
Constructs a new string obtained by replacing all occurrences of pattern with
replacement in s.
This function is generic over all currently supported patterns. The replacement may be a
String or a String.Slice.
Examples:
"red green blue".toSlice.replace 'e' "" = "rd grn blu""red green blue".toSlice.replace (fun c => c == 'u' || c == 'e') "" = "rd grn bl""red green blue".toSlice.replace "e" "" = "rd grn blu""red green blue".toSlice.replace "ee" "E" = "red grEn blue""red green blue".toSlice.replace "e" "E" = "rEd grEEn bluE""aaaaa".toSlice.replace "aa" "b" = "bba""abc".toSlice.replace "" "k" = "kakbkck"
Equations
- One or more equations did not get rendered due to their size.
Instances For
Advances pos as long as pat matches.
Equations
Instances For
Returns the position after the longest prefix of s for which pat matches
(potentially repeatedly).
Equations
- s.skipPrefixWhile pat = s.startPos.skipWhile pat
Instances For
Creates a new slice by removing the longest prefix from 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 = s.sliceFrom (s.skipPrefixWhile pat)
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 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 = s.sliceTo (s.skipPrefixWhile pat)
Instances For
Finds the position of the first match of the pattern pat in a slice s. 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
- One or more equations did not get rendered due to their size.
Instances For
Finds the position of the first match of the pattern pat in a slice s. If there
is no match s.endPos is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.find Char.isWhitespace).get! == ' '"tea".toSlice.find (fun (c : Char) => c == 'X') == "tea".toSlice.endPos("coffee tea water".toSlice.find "tea").get! == 't'
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
- One or more equations did not get rendered due to their size.
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
Instances For
Checks whether a slice only consists of matches of the pattern pat.
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"aaaaaaa".toSlice.all "aa" = false
Equations
- s.all pat = (s.skipPrefixWhile pat == s.endPos)
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 pat s
Instances For
- operating {σ : Slice → Type} {ρ : Type} {pat : ρ} {s : Slice} [Pattern.ToBackwardSearcher pat σ] (currPos : s.Pos) (searcher : Std.Iter (Pattern.SearchStep s)) : RevSplitIterator pat s
- atEnd {σ : Slice → Type} {ρ : Type} {pat : ρ} {s : Slice} [Pattern.ToBackwardSearcher pat σ] : RevSplitIterator pat s
Instances For
Equations
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).toList == ["water".toSlice, "tea".toSlice, "coffee".toSlice]("coffee tea water".toSlice.revSplit ' ').toList == ["water".toSlice, "tea".toSlice, "coffee".toSlice]
Equations
- s.revSplit pat = { internalState := String.Slice.RevSplitIterator.operating s.endPos (String.Slice.Pattern.ToBackwardSearcher.toSearcher pat s) }
Instances For
If pat matches a suffix of s, returns the position at the beginning of the suffix.
Returns none otherwise.
This function is generic over all currently supported patterns.
Equations
Instances For
If pat matches a suffix at pos, returns the position at the beginning of the match.
Returns none otherwise.
This function is generic over all currently supported patterns.
Equations
- pos.revSkip? pat = Option.map String.Slice.Pos.ofSliceTo ((s.sliceTo pos).skipSuffix? 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 suffix.
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.sliceTo (s.skipSuffix? 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
suffix.
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
Rewinds pos as long as pat matches.
Equations
- pos.revSkipWhile pat = match pos.revSkip? pat with | some nextCurr => if nextCurr < pos then nextCurr.revSkipWhile pat else pos | none => pos
Instances For
Returns the position at the start of the longest suffix of s for which pat matches
(potentially repeatedly).
Equations
- s.skipSuffixWhile pat = s.endPos.revSkipWhile pat
Instances For
Checks whether a slice only consists of matches of the pattern pat, starting from the back
of the string.
Short-circuits at the first pattern mis-match.
This function is generic over all currently supported patterns.
For many types of patterns, this function can be expected to return the same result as
Slice.all. If mismatches are expected to occur close to the end of the string, this function
might be more efficient.
For some types of patterns, this function will return a different result than Slice.all.
Consider, for example, a pattern that matches the longest string at the given position that matches
the regular expression "a|aa|ab". Then, given the input string "aab", performing
Slice.all will greedily match the prefix "aa" and then get stuck on the remainder
"b", causing it to return false. On the other hand, Slice.revAll will match
the suffix "ab" and then match the remainder "a", so it will return true.
Examples:
"brown".toSlice.revAll Char.isLower = true"brown and orange".toSlice.revAll Char.isLower = false"aaaaaa".toSlice.revAll 'a' = true"aaaaaa".toSlice.revAll "aa" = true"aaaaaaa".toSlice.revAll "aa" = false
Equations
- s.revAll pat = (s.skipSuffixWhile pat == s.startPos)
Instances For
Creates a new slice by removing the longest suffix from 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 = s.sliceTo (s.skipSuffixWhile pat)
Instances For
Removes trailing whitespace from a slice by moving its end position to just after the last non-whitespace character, or to its start 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 longest suffix 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 = s.sliceFrom (s.skipSuffixWhile pat)
Instances For
Finds the start position of the last match of the pattern pat in a slice, searching
from the end of the slice 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.revFind? Char.isWhitespace).map (·.get!) == some ' '"tea".toSlice.revFind? (fun (c : Char) => c == 'X') == none
Equations
- One or more equations did not get rendered due to their size.
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
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.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz".toSlice.lines.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz\r".toSlice.lines.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz\r".toSlice]
Equations
- s.lines = Std.Iter.map String.Slice.lines.lineMap (s.splitInclusive '\n')