take While Ascii Whitespace(text: string, start: int) - > int- Module
- std.
parser - Receiver
- Not applicable
- Minimum arity
- 2
- Maximum arity
- 2
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.parser in language mode 5.21.
The current compiler selects std/parser.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 386 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 72
Receiver
Parameter constraints
Each scan uses the class named by its corresponding ASCII predicate. The starting position and result follow the zero based scalar positions.
Clamp a negative start to zero. Clamp a start greater than the scalar length to that length. The first position examined is the clamped start.
Inspect consecutive positions from left to right. Stop at the first nonmatching scalar or at the scalar length. Return that exclusive end position.
If the first scalar does not match, return the clamped start. Starting at end of input returns that end. Every scan of an empty string returns zero.
A non ASCII scalar ends the span. Scanning does not skip it, normalize it, or advance across it to find a later match.
The text expression is evaluated before the start expression, once each. Scans do not modify the text or perform I/O. An out of range start produces a bounded result without a diagnostic.
For a clamped start begin and returned end, text. is the matched text. The scan reports a position rather than a character count.
Result
Effects
Failures
Result and effects
LinkClamp the start to the scalar bounds and return the exclusive end of the maximal matching ASCII span.
Related entries
LinkScan a maximal ASCII span
LinkScan a maximal ASCII span
Each scan uses the class named by its corresponding ASCII predicate. The starting position and result follow the zero based scalar positions.
Clamp a negative start to zero. Clamp a start greater than the scalar length to that length. The first position examined is the clamped start.
Inspect consecutive positions from left to right. Stop at the first nonmatching scalar or at the scalar length. Return that exclusive end position.
If the first scalar does not match, return the clamped start. Starting at end of input returns that end. Every scan of an empty string returns zero.
A non ASCII scalar ends the span. Scanning does not skip it, normalize it, or advance across it to find a later match.
The text expression is evaluated before the start expression, once each. Scans do not modify the text or perform I/O. An out of range start produces a bounded result without a diagnostic.
For a clamped start begin and returned end, text. is the matched text. The scan reports a position rather than a character count.
Why
Maximal spans let callers resume at the first unconsumed scalar. Clamping uses the same bounds as string slicing and gives empty input a useful result.
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 352 - compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 359 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1215 -
topaz.stdlib.contract.parser-ascii-spansatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi
Find the exclusive end for every ASCII class
Linkimport std.parserimport std.iolet digit = parser.takeWhileAsciiDigit("123x", 0)let alpha = parser.takeWhileAsciiAlpha("abZ9", 0)let alnum = parser.takeWhileAsciiAlnum("a9Z_", 0)let space = parser.takeWhileAsciiWhitespace("\t\n\r x", 0)io.writeLine("{digit}/{alpha}/{alnum}/{space}")
3/3/3/4
Expected result
Expected result
Execution completes. Exit code 0.
3/3/3/4
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 352 - compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 359 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1215 -
topaz.stdlib.contract.parser-ascii-spansatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi
Stop at non ASCII scalars without changing position units
Linkimport std.parserimport std.iolet digit = parser.takeWhileAsciiDigit("é12x", 1)let combining = parser.takeWhileAsciiAlpha("éA", 0)let suffix = parser.takeWhileAsciiAlpha("éA", 2)let nonbreaking = parser.takeWhileAsciiWhitespace(" ", 0)let alnum = parser.takeWhileAsciiAlnum("Aé", 0)io.writeLine("{digit}/{combining}/{suffix}/{nonbreaking}/{alnum}")
3/1/3/0/1
Expected result
Expected result
Execution completes. Exit code 0.
3/1/3/0/1
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 352 - compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 359 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1215 -
topaz.stdlib.contract.parser-ascii-spansatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi
Clamp starts and keep the first failing position
Linkimport std.parserimport std.iolet text = "12"for start in ([-3, 0, 1, 2, 99]) {let digit = parser.takeWhileAsciiDigit(text, start)let alpha = parser.takeWhileAsciiAlpha(text, start)let alnum = parser.takeWhileAsciiAlnum(text, start)let space = parser.takeWhileAsciiWhitespace(text, start)io.writeLine("{digit}/{alpha}/{alnum}/{space}")}let empty = ""let digit = parser.takeWhileAsciiDigit(empty, 99)let alpha = parser.takeWhileAsciiAlpha(empty, -1)let alnum = parser.takeWhileAsciiAlnum(empty, 0)let space = parser.takeWhileAsciiWhitespace(empty, 1)io.writeLine("{digit}/{alpha}/{alnum}/{space}")
2/0/2/0 2/0/2/0 2/1/2/1 2/2/2/2 2/2/2/2 0/0/0/0
Expected result
Expected result
Execution completes. Exit code 0.
2/0/2/02/0/2/02/1/2/12/2/2/22/2/2/20/0/0/0
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 352 - compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 359 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1215 -
topaz.stdlib.contract.parser-ascii-spansatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi