The Substring type #
This file contains API for Substring type, which is a legacy API that will be replaced by the
safer variant String.Slice.
Equations
Instances For
Copies the region of the underlying string pointed to by a substring into a fresh string.
Equations
- { str := s, startPos := b, stopPos := e }.toString = String.Pos.Raw.extract s b e
Instances For
Instances For
Returns the character at the given position in the substring.
The position is relative to the substring, rather than the underlying string, and no bounds checking
is performed with respect to the substring's end position. If the relative position is not a valid
position in the underlying string, the fallback value (default : Char), which is 'A', is
returned. Does not panic.
Equations
Instances For
Instances For
Returns the next position in a substring after the given position. If the position is at the end of the substring, it is returned unmodified.
Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.
Equations
Instances For
Returns the previous position in a substring, just prior to the given position. If the position is at the beginning of the substring, it is returned unmodified.
Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.
Equations
Instances For
Instances For
Returns the position that's the specified number of characters forward from the given position in a substring. If the end position of the substring is reached, it is returned.
Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.
Instances For
Returns the position that's the specified number of characters prior to the given position in a substring. If the start position of the substring is reached, it is returned.
Both the input position and the returned position are interpreted relative to the substring's start position, not the underlying string.
Instances For
Returns the first character in the substring.
If the substring is empty, but the substring's start position is a valid position in the underlying
string, then the character at the start position is returned. If the substring's start position is
not a valid position in the string, the fallback value (default : Char), which is 'A', is
returned. Does not panic.
Instances For
Instances For
Returns the substring-relative position of the first occurrence of c in s, or s.bsize if c
doesn't occur.
Equations
Instances For
Removes the specified number of characters (Unicode code points) from the beginning of a substring by advancing its start position.
If the substring's end position is reached, the start position is not advanced past it.
Equations
Instances For
Instances For
Removes the specified number of characters (Unicode code points) from the end of a substring by moving its end position towards its start position.
If the substring's start position is reached, the end position is not retracted past it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Retains only the specified number of characters (Unicode code points) at the beginning of a substring, by moving its end position towards its start position.
If the substring's start position is reached, the end position is not retracted past it.
Equations
Instances For
Retains only the specified number of characters (Unicode code points) at the end of a substring, by moving its start position towards its end position.
If the substring's end position is reached, the start position is not advanced past it.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks whether a position in a substring is precisely equal to its ending position.
The position is understood relative to the substring's starting position, rather than the underlying string's starting position.
Instances For
Returns the region of the substring delimited by the provided start and stop positions, as a substring. The positions are interpreted with respect to the substring's start position, rather than the underlying string.
If the resulting substring is empty, then the resulting substring is a substring of the empty string
"". Otherwise, the underlying string is that of the input substring with the beginning and end
positions adjusted.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Splits a substring s on occurrences of the separator string sep. The default separator is " ".
When sep is empty, the result is [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
non-overlapping matches of sep in the string. The separators are not included in the returned
substrings, which are all substrings of s's string.
Equations
Instances For
Folds a function over a substring from the left, accumulating a value starting with init. The
accumulated value is combined with each character in order, using f.
Equations
- Substring.Raw.foldl f init { str := s_1, startPos := b, stopPos := e } = String.foldlAux f s_1 e b init
Instances For
Folds a function over a substring from the right, accumulating a value starting with init. The
accumulated value is combined with each character in reverse order, using f.
Equations
- Substring.Raw.foldr f init { str := s_1, startPos := b, stopPos := e } = String.foldrAux f init s_1 e b
Instances For
Checks whether the Boolean predicate p returns true for any character in a substring.
Short-circuits at the first character for which p returns true.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Retains only the longest prefix of a substring in which a Boolean predicate returns true for all
characters by moving the substring's end position towards its start position.
Equations
Instances For
Instances For
Removes the longest prefix of a substring in which a Boolean predicate returns true for all
characters by moving the substring's start position. The start position is moved to the position of
the first character for which the predicate returns false, or to the substring's end position if
the predicate always returns true.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Retains only the longest suffix of a substring in which a Boolean predicate returns true for all
characters by moving the substring's start position towards its end position.
Equations
- { str := s, startPos := b, stopPos := e }.takeRightWhile x✝ = { str := s, startPos := Substring.Raw.takeRightWhileAux s b x✝ e, stopPos := e }
Instances For
Removes the longest suffix of a substring in which a Boolean predicate returns true for all
characters by moving the substring's end position. The end position is moved just after the position
of the last character for which the predicate returns false, or to the substring's start position
if the predicate always returns true.
Equations
- { str := s, startPos := b, stopPos := e }.dropRightWhile x✝ = { str := s, startPos := b, stopPos := Substring.Raw.takeRightWhileAux s b x✝ e }
Instances For
Removes leading whitespace from a substring 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.
Equations
Instances For
Removes trailing whitespace from a substring by moving its end position to 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.
Equations
Instances For
Removes leading and trailing whitespace from a substring by first moving its start position to the first non-whitespace character, and then moving its end position to the last non-whitespace character.
If the substring consists only of whitespace, then the resulting substring's start position is moved to its end position.
“Whitespace” is defined as characters for which Char.isWhitespace returns true.
Examples:
" red green blue ".toRawSubstring.trim.toString = "red green blue"" red green blue ".toRawSubstring.trim.startPos = ⟨1⟩" red green blue ".toRawSubstring.trim.stopPos = ⟨15⟩" ".toRawSubstring.trim.startPos = ⟨5⟩
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks whether the substring can be interpreted as the decimal representation of a natural number.
A substring can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use Substring.toNat? to convert such a substring to a natural number.
Instances For
Checks whether the substring can be interpreted as the decimal representation of a natural number, returning the number if it can.
A substring can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use Substring.isNat to check whether the substring is such a substring.
Equations
Instances For
Given a Substring, returns another one which has valid endpoints
and represents the same substring according to Substring.toString.
(Note, the substring may still be inverted, i.e. beginning greater than end.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Checks whether two substrings represent equal strings. Usually accessed via the == operator.
Two substrings do not need to have the same underlying string or the same start and end positions; instead, they are equal if they contain the same sequence of characters.
Equations
Instances For
Equations
- Substring.Raw.Internal.beqImpl ss1 ss2 = ss1.beq ss2
Instances For
Equations
- Substring.Raw.hasBeq = { beq := Substring.Raw.beq }
Returns the longest common prefix of two substrings.
The returned substring uses the same underlying string as s.
Equations
- s.commonPrefix t = { str := s.str, startPos := s.startPos, stopPos := Substring.Raw.commonPrefix.loop✝ s t s.startPos t.startPos }
Instances For
Returns the longest common suffix of two substrings.
The returned substring uses the same underlying string as s.
Equations
- s.commonSuffix t = { str := s.str, startPos := Substring.Raw.commonSuffix.loop✝ s t s.stopPos t.stopPos, stopPos := s.stopPos }