Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library

    std.parser.isAsciiAlpha

    Tests the code point at a string position for an ASCII letter.

    isAsciiAlpha(text: string, index: int) -> bool
    Receiver
    Not applicable
    Minimum arity
    2
    Maximum arity
    2

    Declaration and parameters

    Link

    Availability

    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

    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.codePointAt(index) 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.

    Result

    Effects

    Failures

    Result and effects

    Link

    Classify the scalar at a zero based position with the corresponding ASCII code predicate. An absent position returns false.

    Related entries

    Link

    std.parser

    Classify a scalar position

    Link

    Classify 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.codePointAt(index) 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

    Keep scalar positions through multibyte and combining text

    Link
    main.tpzKeep scalar positions through multibyte and combining textOpen in Playground
    1. import std.parser
    2. import std.io
    3. let text = "é5éZ  "
    4. for index in ([0, 1, 2, 3, 4, 5, 6]) {
    5. let digit = parser.isAsciiDigit(text, index)
    6. let alpha = parser.isAsciiAlpha(text, index)
    7. let alnum = parser.isAsciiAlnum(text, index)
    8. let space = parser.isAsciiWhitespace(text, index)
    9. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    10. }
    Expected outputexit 0
    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
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. false/false/false/false
    2. true/false/true/false
    3. false/true/true/false
    4. false/false/false/false
    5. false/true/true/false
    6. false/false/false/false
    7. false/false/false/true
    Source evidence

    Treat negative positions and end of input as false

    Link
    main.tpzTreat negative positions and end of input as falseOpen in Playground
    1. import std.parser
    2. import std.io
    3. let text = "7"
    4. for index in ([-1, 1, 2, 9223372036854775807]) {
    5. let digit = parser.isAsciiDigit(text, index)
    6. let alpha = parser.isAsciiAlpha(text, index)
    7. let alnum = parser.isAsciiAlnum(text, index)
    8. let space = parser.isAsciiWhitespace(text, index)
    9. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    10. }
    11. let empty = ""
    12. let digit = parser.isAsciiDigit(empty, 0)
    13. let alpha = parser.isAsciiAlpha(empty, 0)
    14. let alnum = parser.isAsciiAlnum(empty, 0)
    15. let space = parser.isAsciiWhitespace(empty, 0)
    16. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    Expected outputexit 0
    false/false/false/false
    false/false/false/false
    false/false/false/false
    false/false/false/false
    false/false/false/false
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. false/false/false/false
    2. false/false/false/false
    3. false/false/false/false
    4. false/false/false/false
    5. false/false/false/false
    Source evidence

    Menu

    Download