commit bc4828649ae99fe6586c61fa000598a7a7a8b53e
parent 1a4b32d60edbea3f317358a9e53d58834f16938a
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Sun, 12 Sep 2021 13:43:23 +0200
ascii: implement isblank()
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
1 file changed, 4 insertions(+), 0 deletions(-)
diff --git a/ascii/ctype.ha b/ascii/ctype.ha
@@ -72,6 +72,9 @@ export fn isgraph(c: rune) bool =
export fn iscntrl(c: rune) bool =
if (!isascii(c)) false else cclass[c: u32]&C > 0;
+// Returns true if a rune is a space or a tab.
+export fn isblank(c: rune) bool = (c == ' ' || c == '\t');
+
// Returns true if a rune is a valid ASCII character.
export fn isascii(c: rune) bool = c: u32 <= 0o177;
@@ -99,4 +102,5 @@ export fn tolower(c: rune) rune = {
assert(isascii('a') && isascii('\0') && isascii('\x7F'));
assert(!isascii('\x80') && !isascii('こ'));
assert(tolower('A') == 'a' && tolower('こ') == 'こ');
+ assert(isblank(' ') && isblank('\t') && !isblank('6'));
};