Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека

    std.parser.takeWhileAsciiAlnum

    Finds the end of an ASCII-letter-or-digit span.

    takeWhileAsciiAlnum(text: string, start: int) -> int
    Модуль
    std.parser →
    Получатель
    Неприменимо
    Минимальное число аргументов
    2
    Максимальное число аргументов
    2

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    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.

    Получатель

    Ограничения параметров

    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.slice(begin, end) is the matched text. The scan reports a position rather than a character count.

    Результат

    Эффекты

    Ошибки

    Result and effects

    Ссылка

    Clamp the start to the scalar bounds and return the exclusive end of the maximal matching ASCII span.

    Related entries

    Ссылка

    std.parser →

    Scan a maximal ASCII span

    Ссылка
    Правилоtopaz.stdlib.contract.parser-ascii-spans.rule

    Scan 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.slice(begin, end) is the matched text. The scan reports a position rather than a character count.

    Причина

    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.

    Find the exclusive end for every ASCII class

    Ссылка
    main.tpzFind the exclusive end for every ASCII classОткрыть песочницу →
    1. import std.parser
    2. import std.io
    3. let digit = parser.takeWhileAsciiDigit("123x", 0)
    4. let alpha = parser.takeWhileAsciiAlpha("abZ9", 0)
    5. let alnum = parser.takeWhileAsciiAlnum("a9Z_", 0)
    6. let space = parser.takeWhileAsciiWhitespace("\t\n\r x", 0)
    7. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    Ожидаемый выводКод завершения 0
    3/3/3/4
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 3/3/3/4

    Stop at non ASCII scalars without changing position units

    Ссылка
    main.tpzStop at non ASCII scalars without changing position unitsОткрыть песочницу →
    1. import std.parser
    2. import std.io
    3. let digit = parser.takeWhileAsciiDigit("é12x", 1)
    4. let combining = parser.takeWhileAsciiAlpha("éA", 0)
    5. let suffix = parser.takeWhileAsciiAlpha("éA", 2)
    6. let nonbreaking = parser.takeWhileAsciiWhitespace("  ", 0)
    7. let alnum = parser.takeWhileAsciiAlnum("Aé", 0)
    8. io.writeLine("{digit}/{combining}/{suffix}/{nonbreaking}/{alnum}")
    Ожидаемый выводКод завершения 0
    3/1/3/0/1
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 3/1/3/0/1

    Clamp starts and keep the first failing position

    Ссылка
    main.tpzClamp starts and keep the first failing positionОткрыть песочницу →
    1. import std.parser
    2. import std.io
    3. let text = "12"
    4. for start in ([-3, 0, 1, 2, 99]) {
    5. let digit = parser.takeWhileAsciiDigit(text, start)
    6. let alpha = parser.takeWhileAsciiAlpha(text, start)
    7. let alnum = parser.takeWhileAsciiAlnum(text, start)
    8. let space = parser.takeWhileAsciiWhitespace(text, start)
    9. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    10. }
    11. let empty = ""
    12. let digit = parser.takeWhileAsciiDigit(empty, 99)
    13. let alpha = parser.takeWhileAsciiAlpha(empty, -1)
    14. let alnum = parser.takeWhileAsciiAlnum(empty, 0)
    15. let space = parser.takeWhileAsciiWhitespace(empty, 1)
    16. io.writeLine("{digit}/{alpha}/{alnum}/{space}")
    Ожидаемый выводКод завершения 0
    2/0/2/0
    2/0/2/0
    2/1/2/1
    2/2/2/2
    2/2/2/2
    0/0/0/0
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. 2/0/2/0
    2. 2/0/2/0
    3. 2/1/2/1
    4. 2/2/2/2
    5. 2/2/2/2
    6. 0/0/0/0

    Меню

    Загрузка →