File: ctype.h

package info (click to toggle)
crust-firmware 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: ansic: 19,341; yacc: 596; lex: 479; makefile: 334; asm: 215; sh: 136; python: 42
file content (58 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright © 2005-2014 Rich Felker, et al.
 * Copyright © 2017-2022 The Crust Firmware Authors.
 * SPDX-License-Identifier: MIT
 */

#ifndef STDLIB_CTYPE_H
#define STDLIB_CTYPE_H

#include <stdbool.h>

#define isalpha(a) (((unsigned)(a) | 32) - 'a' < 26)
#define isascii(a) ((unsigned)(a) < 128)
#define isdigit(a) ((unsigned)(a) - '0' < 10)
#define isgraph(a) ((unsigned)(a) - 0x21 < 0x5e)
#define islower(a) ((unsigned)(a) - 'a' < 26)
#define isprint(a) ((unsigned)(a) - 0x20 < 0x5f)
#define isupper(a) ((unsigned)(a) - 'A' < 26)
#define tolower(a) ((a) | 0x20)
#define toupper(a) ((a) & 0x5f)

static inline bool
isalnum(char c)
{
	return isalpha(c) || isdigit(c);
}

static inline bool
isblank(char c)
{
	return c == ' ' || c == '\t';
}

static inline bool
iscntrl(char c)
{
	return (unsigned)c < 0x20 || c == 0x7f;
}

static inline bool
ispunct(char c)
{
	return isgraph(c) && !isalnum(c);
}

static inline bool
isspace(char c)
{
	return c == ' ' || (unsigned)c - '\t' < 5;
}

static inline bool
isxdigit(char c)
{
	return isdigit(c) || ((unsigned)c | 32) - 'a' < 6;
}

#endif /* STDLIB_CTYPE_H */