summaryrefslogtreecommitdiff
path: root/include/system/ctype.h
blob: 65e7348ff17472c66e887fbdbaee7a0e594b9907 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: BSD-2-Clause-Patent
/*
 * ctype.h - standard ctype functions
 */
#ifdef SHIM_UNIT_TEST
#include_next <ctype.h>
#else
#ifndef _CTYPE_H
#define _CTYPE_H

#define isprint(c) ((c) >= 0x20 && (c) <= 0x7e)

/* Determines if a particular character is a decimal-digit character */
static inline __attribute__((__unused__)) int
isdigit(int c)
{
	//
	// <digit> ::= [0-9]
	//
	return (('0' <= (c)) && ((c) <= '9'));
}

/* Determine if an integer represents character that is a hex digit */
static inline __attribute__((__unused__)) int
isxdigit(int c)
{
	//
	// <hexdigit> ::= [0-9] | [a-f] | [A-F]
	//
	return ((('0' <= (c)) && ((c) <= '9')) ||
	        (('a' <= (c)) && ((c) <= 'f')) ||
	        (('A' <= (c)) && ((c) <= 'F')));
}

/* Determines if a particular character represents a space character */
static inline __attribute__((__unused__)) int
isspace(int c)
{
	//
	// <space> ::= [ ]
	//
	return ((c) == ' ');
}

/* Determine if a particular character is an alphanumeric character */
static inline __attribute__((__unused__)) int
isalnum(int c)
{
	//
	// <alnum> ::= [0-9] | [a-z] | [A-Z]
	//
	return ((('0' <= (c)) && ((c) <= '9')) ||
	        (('a' <= (c)) && ((c) <= 'z')) ||
	        (('A' <= (c)) && ((c) <= 'Z')));
}

/* Determines if a particular character is in upper case */
static inline __attribute__((__unused__)) int
isupper(int c)
{
	//
	// <uppercase letter> := [A-Z]
	//
	return (('A' <= (c)) && ((c) <= 'Z'));
}

/* Convert character to lowercase */
static inline __attribute__((__unused__)) int
tolower(int c)
{
	if (('A' <= (c)) && ((c) <= 'Z')) {
		return (c - ('A' - 'a'));
	}
	return (c);
}

static inline __attribute__((__unused__)) int
toupper(int c)
{
	return ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c);
}

#endif /* !_CTYPE_H */
#endif /* !SHIM_UNIT_TEST */
// vim:fenc=utf-8:tw=75:noet