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".replace 'e' "" = "rd grn blu""red green blue".replace (fun c => c == 'u' || c == 'e') "" = "rd grn bl""red green blue".replace "e" "" = "rd grn blu""red green blue".replace "ee" "E" = "red grEn blue""red green blue".replace "e" "E" = "rEd grEEn bluE""aaaaa".replace "aa" "b" = "bba""abc".replace "" "k" = "kakbkck"
Instances For
Finds the position of the first match of the pattern pattern in after the position
pos. If there is no match none is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.startPos.find? Char.isWhitespace).map (·.get!) == some ' '("tea".toSlice.pos ⟨1⟩ (by decide)).find? (fun (c : Char) => c == 't') == none
Equations
- pos.find? pattern = Option.map String.Slice.Pos.ofSliceFrom ((s.sliceFrom pos).find? pattern)
Instances For
Finds the position of the first match of the pattern pattern in after the position
pos. If there is no match s.endPos is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".toSlice.startPos.find Char.isWhitespace).get! == ' '("tea".toSlice.pos ⟨1⟩ (by decide)).find (fun (c : Char) => c == 't') == "tea".toSlice.endPos
Equations
- pos.find pattern = String.Slice.Pos.ofSliceFrom ((s.sliceFrom pos).find pattern)
Instances For
Finds the position of the first match of the pattern pattern in after the position
pos. If there is no match none is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".startPos.find? Char.isWhitespace).map (·.get!) == some ' '("tea".pos ⟨1⟩ (by decide)).find? (fun (c : Char) => c == 't') == none
Equations
- pos.find? pattern = Option.map String.Pos.ofToSlice (pos.toSlice.find? pattern)
Instances For
Finds the position of the first match of the pattern pattern in after the position
pos. If there is no match s.endPos is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".startPos.find Char.isWhitespace).get! == ' '("tea".pos ⟨1⟩ (by decide)).find (fun (c : Char) => c == 't') == "tea".endPos
Equations
- pos.find pattern = String.Pos.ofToSlice (pos.toSlice.find pattern)
Instances For
Finds the position of the first match of the pattern pattern in a string s. If
there is no match none is returned.
This function is generic over all currently supported patterns.
Examples:
("coffee tea water".find? Char.isWhitespace).map (·.get!) == some ' '"tea".find? (fun (c : Char) => c == 'X') == none("coffee tea water".find? "tea").map (·.get!) == some 't'
Instances For
Finds the position of the first match of the pattern pattern 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".find Char.isWhitespace).get! == ' '"tea".find (fun (c : Char) => c == 'X') == "tea".endPos("coffee tea water".find "tea").get! == 't'
Instances For
Finds the position of the first match of the pattern pattern in a slice s that is
strictly before pos. If there is no such match none is returned.
This function is generic over all currently supported patterns except
String/String.Slice.
Examples:
(("abc".toSlice.endPos.prev (by decide)).revFind? Char.isAlpha).map (·.get!) == some 'b'"abc".toSlice.startPos.revFind? Char.isAlpha == none
Equations
- pos.revFind? pattern = Option.map String.Slice.Pos.ofSliceTo ((s.sliceTo pos).revFind? pattern)
Instances For
Finds the position of the first match of the pattern pattern in a slice s that is
strictly before pos. If there is no such match none is returned.
This function is generic over all currently supported patterns except
String/String.Slice.
Examples:
(("ab1c".endPos.prev (by decide)).revFind? Char.isAlpha).map (·.get!) == some 'b'"abc".startPos.revFind? Char.isAlpha == none
Equations
- pos.revFind? pattern = Option.map String.Pos.ofToSlice (pos.toSlice.revFind? pattern)
Instances For
Finds the position of the first match of the pattern pattern in a string, 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.revFind? Char.isWhitespace).map (·.get!) == some ' '"tea".toSlice.revFind? (fun (c : Char) => c == 'X') == none
Instances For
Returns the position of the beginning of the line that contains the position pos.
Lines are ended by '\n', and the returned position is either 0 : String.Pos.Raw or
immediately after a '\n' character.
Equations
Instances For
Splits a string 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".split Char.isWhitespace).toList == ["coffee".toSlice, "tea".toSlice, "water".toSlice]("coffee tea water".split ' ').toList == ["coffee".toSlice, "tea".toSlice, "water".toSlice]("coffee tea water".split " tea ").toList == ["coffee".toSlice, "water".toSlice]("ababababa".split "aba").toList == ["coffee".toSlice, "water".toSlice]("baaab".split "aa").toList == ["b".toSlice, "ab".toSlice]
Instances For
Splits a string 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".splitInclusive Char.isWhitespace).toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".splitInclusive ' ').toList == ["coffee ".toSlice, "tea ".toSlice, "water".toSlice]("coffee tea water".splitInclusive " tea ").toList == ["coffee tea ".toSlice, "water".toSlice]("baaab".splitInclusive "aa").toList == ["baa".toSlice, "ab".toSlice]
Equations
- s.splitInclusive pat = s.toSlice.splitInclusive pat
Instances For
Equations
- String.foldlAux f s stopPos i a = String.Slice.foldl f a (s.slice! (s.pos! i) (s.pos! stopPos))
Instances For
Folds a function over a string 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".foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 2"coffee tea and water".foldl (fun n c => if c.isWhitespace then n + 1 else n) 0 = 3"coffee tea water".foldl (·.push ·) "" = "coffee tea water"
Equations
- String.foldl f init s = String.Slice.foldl f init s.toSlice
Instances For
Equations
- String.Internal.foldlImpl f init s = String.foldl f init s
Instances For
Equations
- String.foldrAux f a s i begPos = String.Slice.foldr f a (s.slice! (s.pos! begPos) (s.pos! i))
Instances For
Folds a function over a string from the right, accumulating a value starting with init. The
accumulated value is combined with each character in reverse order, using f.
Examples:
"coffee tea water".foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 2"coffee tea and water".foldr (fun c n => if c.isWhitespace then n + 1 else n) 0 = 3"coffee tea water".foldr (fun c s => s.push c) "" = "retaw aet eeffoc"
Equations
- String.foldr f init s = String.Slice.foldr f init s.toSlice
Instances For
Checks whether a string has a match of the pattern pat anywhere.
This function is generic over all currently supported patterns.
Examples:
"coffee tea water".contains Char.isWhitespace = true"tea".contains (fun (c : Char) => c == 'X') = false"coffee tea water".contains "tea" = true
Instances For
Equations
- String.Internal.containsImpl s c = s.contains c
Instances For
Checks whether a string has a match of the pattern pat anywhere.
This function is generic over all currently supported patterns.
Examples:
"coffee tea water".contains Char.isWhitespace = true"tea".contains (fun (c : Char) => c == 'X') = false"coffee tea water".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".all Char.isLower = true"brown and orange".all Char.isLower = false"aaaaaa".all 'a' = true"aaaaaa".all "aa" = true"aaaaaaa".all "aa" = false
Instances For
Checks whether the string 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:
"".isNat = false"0".isNat = true"5".isNat = true"05".isNat = true"587".isNat = true"-587".isNat = false" 5".isNat = false"2+3".isNat = false"0xff".isNat = false
Instances For
Interprets a string 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:
"".toNat? = none"0".toNat? = some 0"5".toNat? = some 5"587".toNat? = some 587"-587".toNat? = none" 5".toNat? = none"2+3".toNat? = none"0xff".toNat? = none
Instances For
Interprets a string 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:
Instances For
Interprets a string as the decimal representation of an integer, returning it. Returns none
if the string does not contain a decimal integer.
A string can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Leading + characters are not allowed.
Use String.isInt to check whether String.toInt?
would return some. String.toInt! is an
alternative that panics instead of returning none when the string is not an integer.
Examples:
"".toInt? = none"-".toInt? = none"0".toInt? = some 0"5".toInt? = some 5"-5".toInt? = some (-5)"587".toInt? = some 587"-587".toInt? = some (-587)" 5".toInt? = none"2-3".toInt? = none"0xff".toInt? = none
Instances For
Checks whether the string can be interpreted as the decimal representation of an integer.
A string can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Leading + characters are not allowed.
Use String.toInt? or String.toInt! to convert
such a string to an integer.
Examples:
"".isInt = false"-".isInt = false"0".isInt = true"-0".isInt = true"5".isInt = true"587".isInt = true"-587".isInt = true"+587".isInt = false" 5".isInt = false"2-3".isInt = false"0xff".isInt = false
Instances For
Interprets a string as the decimal representation of an integer, returning it. Panics if the string does not contain a decimal integer.
A string can be interpreted as a decimal integer if it only consists of at least one decimal digit
and optionally - in front. Leading + characters are not allowed.
Use String.isInt to check whether String.toInt! would return a value.
String.toInt? is a safer alternative that returns none instead of panicking when the
string is not an integer.
Examples:
Instances For
Equations
Instances For
Creates an iterator over all valid positions within s.
Examples
("abc".positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', 'c']("abc".positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2]("ab∀c".positions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['a', 'b', '∀', 'c']("ab∀c".positions.map (·.val.offset.byteIdx) |>.toList) = [0, 1, 2, 5]
Instances For
Creates an iterator over all valid positions within s, starting from the last valid
position and iterating towards the first one.
Examples
("abc".revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', 'b', 'a']("abc".revPositions.map (·.val.offset.byteIdx) |>.toList) = [2, 1, 0]("ab∀c".revPositions.map (fun ⟨p, h⟩ => p.get h) |>.toList) = ['c', '∀', 'b', 'a']("ab∀c".toSlice.revPositions.map (·.val.offset.byteIdx) |>.toList) = [5, 2, 1, 0]
Equations
Instances For
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".revChars.toList = ['c', 'b', 'a']"ab∀c".revChars.toList = ['c', '∀', 'b', 'a']
Instances For
Creates an iterator over all bytes in s.
Examples:
"abc".byteIterator.toList = [97, 98, 99]"ab∀c".byteIterator.toList = [97, 98, 226, 136, 128, 99]
Equations
- s.byteIterator = s.toSlice.bytes
Instances For
Creates an iterator over all bytes in s, starting from the last one and iterating towards
the first one.
Examples:
"abc".revBytes.toList = [99, 98, 97]"ab∀c".revBytes.toList = [99, 128, 136, 226, 98, 97]
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".lines.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz".lines.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz".toSlice]"foo\r\nbar\n\nbaz\r".lines.toList == ["foo".toSlice, "bar".toSlice, "".toSlice, "baz\r".toSlice]