take While Ascii Whitespace(text: string, start: int) - > int- 수신자
- 해당 없음
- 최소 인자 수
- 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. 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
링크Scan a maximal ASCII span
링크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. 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
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
3/3/3/4
Stop at non ASCII scalars without changing position units
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
3/1/3/0/1
Clamp starts and keep the first failing position
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
2/0/2/02/0/2/02/1/2/12/2/2/22/2/2/20/0/0/0