summaryrefslogtreecommitdiff
path: root/src/libc/ctype.c
blob: fa49a07723e17dc9aaeab4f8c24847ab7fd871a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <ctype.h>

int isalnum(int c) {
	return isalpha(c) || isdigit(c);
}

int isalpha(int c) {
	return islower(c) || isupper(c);
}

int iscntrl(int c) {
	return c <= 0x1f || c == 0x7f;
}

int isdigit(int c) {
	return '0' <= c && c <= '9';
}

int isgraph(int c) {
	return isalpha(c) || isdigit(c) || ispunct(c);
}

int islower(int c) {
	return 'a' <= c && c <= 'z';
}

int isprint(int c) {
	return isgraph(c) || c == ' ';
}

int ispunct(int c) {
	return ('!' <= c && c <= '/')
		|| (':' <= c && c <= '@')
		|| ('[' <= c && c <= '`')
		|| ('{' <= c && c <= '~');
}

int isspace(int c) {
	return c == ' '
		|| c == '\f'
		|| c == '\n'
		|| c == '\r'
		|| c == '\t'
		|| c == '\v';
}

int isupper(int c) {
	return 'A' <= c && c <= 'Z';
}

int isxdigit(int c) {
	return ('0' <= c && c <= '9')
		|| ('A' <= c && c <= 'F')
		|| ('a' <= c && c <= 'f');
}

int tolower(int c) {
	if (isupper(c)) return c - 'A' + 'a';
	return c;
}

int toupper(int c) {
	if (islower(c)) return c - 'a' + 'A';
	return c;
}