CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
ctype.h
Go to the documentation of this file.
1
// Copyright Microsoft and CHERIoT Contributors.
2
// SPDX-License-Identifier: MIT
3
#pragma once
4
5
/**
6
* \file
7
*
8
* ASCII-only definition of C standard C functions.
9
*
10
* These functions are explicitly not locale aware. Apart from `isascii`,
11
* their return values are unspecified for non-ASCII character sets. Most
12
* embedded software does not need to be locale aware and talks to some back
13
* end that handles localisation. If you require support for Unicode or other
14
* non-ASCII character sets, do not use this file.
15
*/
16
17
/**
18
* Returns true if `c` is a 7-bit ASCII character, false otherwise. The value
19
* of `c` must be some ASCII-superset encoding, such as Unicode or an 8-bit code
20
* page.
21
*/
22
static
inline
int
isascii
(
int
c)
23
{
24
return
(c & ~0x7F) == 0;
25
}
26
27
/**
28
* Returns true if `c` is an ASCII digit character, false otherwise.
29
*/
30
static
inline
int
isdigit
(
int
c)
31
{
32
return
c >=
'0'
&& c <=
'9'
;
33
}
34
35
/**
36
* Returns true if `c` is an ASCII lowercase character, false otherwise.
37
*/
38
static
inline
int
islower
(
int
c)
39
{
40
return
(c >=
'a'
) && (c <=
'z'
);
41
}
42
43
/**
44
* Returns true if `c` is an ASCII printable character, false otherwise.
45
*/
46
static
inline
int
isprint
(
int
c)
47
{
48
return
c >=
'\x20'
&& c <=
'\x7e'
;
49
}
50
51
/**
52
* Returns true if `c` is an ASCII whitespace character, false otherwise.
53
*/
54
static
inline
int
isspace
(
int
c)
55
{
56
switch
(c)
57
{
58
default
:
59
return
0;
60
case
'\t'
:
61
case
'\n'
:
62
case
'\v'
:
63
case
'\f'
:
64
case
'\r'
:
65
case
' '
:
66
return
1;
67
}
68
}
69
70
/**
71
* Returns true if `c` is an ASCII uppercase character, false otherwise.
72
*/
73
static
inline
int
isupper
(
int
c)
74
{
75
return
(c >=
'A'
) && (c <=
'Z'
);
76
}
77
78
/**
79
* Returns true if `c` is an ASCII character that is part of the Latin
80
* alphabet, false otherwise.
81
*/
82
static
inline
int
isalpha
(
int
c)
83
{
84
return
islower
(c) ||
isupper
(c);
85
}
86
87
/**
88
* Returns true if `c` is an ASCII hexadecimal digit (0-f), false otherwise.
89
*/
90
static
inline
int
isxdigit
(
int
c)
91
{
92
return
isdigit
(c) || ((c >=
'A'
) && (c <=
'F'
)) ||
93
((c >=
'a'
) && (c <=
'f'
));
94
}
95
96
/**
97
* Converts an uppercase ASCII character to a lowercase one, or returns the
98
* original value if `c` is not an uppercase character.
99
*/
100
static
inline
int
tolower
(
int
c)
101
{
102
return
c + (
isupper
(c) ? c : 0);
103
}
104
105
/**
106
* Converts a lowercase ASCII character to a uppercase one, or returns the
107
* original value if `c` is not an lowercase character.
108
*/
109
static
inline
int
toupper
(
int
c)
110
{
111
return
c - (
islower
(c) ? c : 0);
112
}
islower
static int islower(int c)
Returns true if c is an ASCII lowercase character, false otherwise.
Definition
ctype.h:38
isupper
static int isupper(int c)
Returns true if c is an ASCII uppercase character, false otherwise.
Definition
ctype.h:73
tolower
static int tolower(int c)
Converts an uppercase ASCII character to a lowercase one, or returns the original value if c is not a...
Definition
ctype.h:100
isascii
static int isascii(int c)
Returns true if c is a 7-bit ASCII character, false otherwise.
Definition
ctype.h:22
isspace
static int isspace(int c)
Returns true if c is an ASCII whitespace character, false otherwise.
Definition
ctype.h:54
isprint
static int isprint(int c)
Returns true if c is an ASCII printable character, false otherwise.
Definition
ctype.h:46
isalpha
static int isalpha(int c)
Returns true if c is an ASCII character that is part of the Latin alphabet, false otherwise.
Definition
ctype.h:82
toupper
static int toupper(int c)
Converts a lowercase ASCII character to a uppercase one, or returns the original value if c is not an...
Definition
ctype.h:109
isdigit
static int isdigit(int c)
Returns true if c is an ASCII digit character, false otherwise.
Definition
ctype.h:30
isxdigit
static int isxdigit(int c)
Returns true if c is an ASCII hexadecimal digit (0-f), false otherwise.
Definition
ctype.h:90
Generated by
1.18.0