Interprets a string as the decimal representation of a natural number, returning it. Panics if the string does not contain a decimal natural number.
A string can be interpreted as a decimal natural number if it is not empty and all the characters in it are digits.
Use String.isNat to check whether String.toNat! would return a value. String.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.
Instances For
Equations
- String.utf8DecodeChar? a i = a.utf8DecodeChar? i
Instances For
Checks whether an array of bytes is a valid UTF-8 encoding of a string.
Equations
Instances For
Moves the iterator forward until the Boolean predicate p returns true for the iterator's current
character or until the end of the string is reached. Does nothing if the current character already
satisfies p.
Equations
Instances For
Iterates over a string, updating a state at each character using the provided function f, until
f returns none. Begins with the state init. Returns the state and character for which f
returns none.
Equations
Instances For
Consistently de-indents the lines in a string, removing the same amount of leading whitespace from each line such that the least-indented line has no leading whitespace.
The number of leading whitespace characters to remove from each line is determined by counting the
number of leading space (' ') and tab ('\t') characters on lines after the first line that also
contain non-whitespace characters. No distinction is made between tab and space characters; both
count equally.
The least number of leading whitespace characters found is then removed from the beginning of each line. The first line's leading whitespace is not counted when determining how far to de-indent the string, but leading whitespace is removed from it.
Examples:
"Here:\n fun x =>\n x + 1".removeLeadingSpaces = "Here:\nfun x =>\n x + 1""Here:\n\t\tfun x =>\n\t \tx + 1".removeLeadingSpaces = "Here:\nfun x =>\n \tx + 1""Here:\n\t\tfun x =>\n \n\t \tx + 1".removeLeadingSpaces = "Here:\nfun x =>\n\n \tx + 1"
Equations
Instances For
Replaces each \r\n with \n to normalize line endings, but does not validate that there are no
isolated \r characters.
This is an optimized version of String.replace text "\r\n" "\n".
Equations
- text.crlfToLf = String.crlfToLf.go✝ text "" 0 0