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.
Converts a Substring.Raw into a String.Slice, returning none if the substring is invalid.
Equations
Instances For
Checks whether a substring is empty.
A substring is empty if its start and end positions are the same.
Equations
Instances For
Equations
Instances For
{} Copies the region of the underlying string pointed to by a substring into a fresh string.
Equations
Instances For
Equations
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
Equations
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
Equations
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.
Equations
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.
Equations
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.
Equations
Instances For
Equations
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
Equations
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
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
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.
Equations
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
Instances For
Equations
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
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
Instances For
Checks whether a substring contains the specified character.
Equations
Instances For
Equations
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
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
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
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. Underscores ({lit}_) are allowed as digit separators for readability, but cannot appear
at the start, at the end, or consecutively.
Use Substring.toNat? to convert such a substring to a natural number.
Equations
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. Underscores ({lit}_) are allowed as digit separators and are ignored during parsing.
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
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
Instances For
Checks whether two substrings have the same position and content.
The two substrings do not need to have the same underlying string for this check to succeed.
Equations
Instances For
Returns the longest common prefix of two substrings.
The returned substring uses the same underlying string as s.
Equations
Instances For
Returns the longest common suffix of two substrings.
The returned substring uses the same underlying string as s.