diff options
| author | Shawn Landden <shawn@git.icu> | 2019-03-21 20:33:37 -0600 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-22 16:25:56 -0400 |
| commit | b76398c9939372ebd2e7263e2aec76503f48b146 (patch) | |
| tree | 6f6c2ede6afb8818bdb5e74e535e87fb1ff78942 /src/analyze.cpp | |
| parent | 6272847917be186fa83f92b0580ed27f459014bd (diff) | |
| download | zig-b76398c9939372ebd2e7263e2aec76503f48b146.tar.gz zig-b76398c9939372ebd2e7263e2aec76503f48b146.zip | |
std: add ascii with C ASCII character classes
Does NOT look at the locale the way the C functions do.
int isalnum(int c);
int isalpha(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
int isascii(int c);
int isblank(int c);
int toupper(int c);
int tolower(int c);
Tested to match glibc (when using C locale) with this program:
const c = @cImport({
// See https://github.com/ziglang/zig/issues/515
@cDefine("_NO_CRT_STDIO_INLINE", "1");
@cInclude("stdio.h");
@cInclude("string.h");
@cInclude("ctype.h");
});
const std = @import("std");
const ascii = std.ascii;
const abort = std.os.abort;
export fn main(argc: c_int, argv: **u8) c_int {
var i: u8 = undefined;
i = 0;
while (true) {
if (ascii.isAlNum(i) != (c.isalnum(i) > 0)) { abort(); }
if (ascii.isAlpha(i) != (c.isalpha(i) > 0)) { abort(); }
if (ascii.isCtrl(i) != (c.iscntrl(i) > 0)) { abort(); }
if (ascii.isDigit(i) != (c.isdigit(i) > 0)) { abort(); }
if (ascii.isGraph(i) != (c.isgraph(i) > 0)) { abort(); }
if (ascii.isLower(i) != (c.islower(i) > 0)) { abort(); }
if (ascii.isPrint(i) != (c.isprint(i) > 0)) { abort(); }
if (ascii.isPunct(i) != (c.ispunct(i) > 0)) { abort(); }
if (ascii.isSpace(i) != (c.isspace(i) > 0)) { abort(); }
if (ascii.isUpper(i) != (c.isupper(i) > 0)) { abort(); }
if (ascii.isXDigit(i) != (c.isxdigit(i) > 0)) { abort(); }
if (i == 255) { break; }
i += 1;
}
_ = c.printf(c"Success!\n");
return 0;
}
Diffstat (limited to 'src/analyze.cpp')
0 files changed, 0 insertions, 0 deletions
