is Ascii Alpha(text: string, index: int) - > bool- 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· 331 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 72
Receiver
Parameter constraints
The index counts Unicode scalars from zero. A multibyte scalar occupies one position. A combining scalar occupies its own position.
A present scalar is classified by the corresponding code predicate. Non ASCII scalars return false, including a nonbreaking space and letters outside the ASCII ranges.
A negative index or an index at or beyond the scalar length returns false. Index zero in an empty string also returns false. These cases do not produce a diagnostic.
The result agrees with applying the corresponding code predicate to text. when it returns Some(code). A None() result means false.
The text expression is evaluated before the index expression, once each. Classification leaves the string unchanged and performs no I/O.
Related rule: Classify a scalar positionResult
Effects
Failures
Result and effects
LinkClassify the scalar at a zero based position with the corresponding ASCII code predicate. An absent position returns false.
Related entries
LinkClassify a scalar position
LinkClassify a scalar position
The index counts Unicode scalars from zero. A multibyte scalar occupies one position. A combining scalar occupies its own position.
A present scalar is classified by the corresponding code predicate. Non ASCII scalars return false, including a nonbreaking space and letters outside the ASCII ranges.
A negative index or an index at or beyond the scalar length returns false. Index zero in an empty string also returns false. These cases do not produce a diagnostic.
The result agrees with applying the corresponding code predicate to text. when it returns Some(code). A None() result means false.
The text expression is evaluated before the index expression, once each. Classification leaves the string unchanged and performs no I/O.
Why
A shared scalar coordinate system lets parser positions pass directly to string operations. An absent position is a failed predicate, so end of input needs no exceptional control flow.
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 324 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1148 -
topaz.stdlib.contract.parser-ascii-positionsatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi
Keep scalar positions through multibyte and combining text
Linkimport std.parserimport std.iolet text = "é5éZ "for index in ([0, 1, 2, 3, 4, 5, 6]) {let digit = parser.isAsciiDigit(text, index)let alpha = parser.isAsciiAlpha(text, index)let alnum = parser.isAsciiAlnum(text, index)let space = parser.isAsciiWhitespace(text, index)io.writeLine("{digit}/{alpha}/{alnum}/{space}")}
false/false/false/false true/false/true/false false/true/true/false false/false/false/false false/true/true/false false/false/false/false false/false/false/true
Expected result
Expected result
Execution completes. Exit code 0.
false/false/false/falsetrue/false/true/falsefalse/true/true/falsefalse/false/false/falsefalse/true/true/falsefalse/false/false/falsefalse/false/false/true
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 324 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1148 -
topaz.stdlib.contract.parser-ascii-positionsatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi
Treat negative positions and end of input as false
Linkimport std.parserimport std.iolet text = "7"for index in ([-1, 1, 2, 9223372036854775807]) {let digit = parser.isAsciiDigit(text, index)let alpha = parser.isAsciiAlpha(text, index)let alnum = parser.isAsciiAlnum(text, index)let space = parser.isAsciiWhitespace(text, index)io.writeLine("{digit}/{alpha}/{alnum}/{space}")}let empty = ""let digit = parser.isAsciiDigit(empty, 0)let alpha = parser.isAsciiAlpha(empty, 0)let alnum = parser.isAsciiAlnum(empty, 0)let space = parser.isAsciiWhitespace(empty, 0)io.writeLine("{digit}/{alpha}/{alnum}/{space}")
false/false/false/false false/false/false/false false/false/false/false false/false/false/false false/false/false/false
Expected result
Expected result
Execution completes. Exit code 0.
false/false/false/falsefalse/false/false/falsefalse/false/false/falsefalse/false/false/falsefalse/false/false/false
Source evidence
- compiler/crates/topaz_resolve/src/stdlib.rs at
912a5e86e1f9· 324 - compiler/crates/topaz_value/src/value/members.rs at
912a5e86e1f9· 1148 -
topaz.stdlib.contract.parser-ascii-positionsatworking-tree - topaz.decision.parser-scalar-ascii.1 at
topaz.decisi