aboutsummaryrefslogtreecommitdiff
path: root/arch/all/core/include/ctype.h
blob: 186b695192bc1a546bd1caa5b540e8b1a5fdf0a3 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ****************************************************************************
 * ctype.h -- Character type.
 *
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'all/core' module in libcarrot, an experimental
 * modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#include <cdefs.h>
__BEGIN_DECLS

/* ************************************************************************* */
/*  Symbols (if no macros)                                                   */
/* ************************************************************************* */
/* check type */
__BEGIN_NAMESPACE_STD
extern __pure int isalnum  _OF((int __c)) __THROW;
extern __pure int isalpha  _OF((int __c)) __THROW;
extern __pure int isascii  _OF((int __c)) __THROW;
extern __pure int iscntrl  _OF((int __c)) __THROW;
extern __pure int isdigit  _OF((int __c)) __THROW;
extern __pure int isgraph  _OF((int __c)) __THROW;
extern __pure int islower  _OF((int __c)) __THROW;
extern __pure int isprint  _OF((int __c)) __THROW;
extern __pure int ispunct  _OF((int __c)) __THROW;
extern __pure int isspace  _OF((int __c)) __THROW;
extern __pure int isupper  _OF((int __c)) __THROW;
extern __pure int isxdigit _OF((int __c)) __THROW;
__END_NAMESPACE_STD
__BEGIN_NAMESPACE_C99
extern __pure int isblank  _OF((int __c))  __THROW;
__END_NAMESPACE_C99

/* convert to lower or upper */
__BEGIN_NAMESPACE_STD
extern __pure int tolower  _OF((int __c)) __THROW;
extern __pure int toupper  _OF((int __c)) __THROW;
extern __pure int toascii  _OF((int __c)) __THROW;
__END_NAMESPACE_STD
/* ************************************************************************* */
/*  Macros for interacting with the tab                                      */
/* ************************************************************************* */
/* Prepare the bits generation */
#include <endian.h>
#if __BYTE_ORDER == __BIG_ENDIAN
# define _ISbit(bit) (1 << (bit))
#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
# define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
#endif

/* Make the bits */
#define _ISupper  _ISbit(0)  /* uppercase */
#define _ISlower  _ISbit(1)  /* lowercase */
#define _ISalpha  _ISbit(2)  /* alphabetic */
#define _ISdigit  _ISbit(3)  /* numeric */
#define _ISxdigit _ISbit(4)  /* hexadecimal numeric */
#define _ISspace  _ISbit(5)  /* whitespace */
#define _ISprint  _ISbit(6)  /* printable */
#define _ISgraph  _ISbit(7)  /* Graphical */
#define _ISblank  _ISbit(8)  /* Blank */
#define _IScntrl  _ISbit(9)  /* Control character */
#define _ISpunct  _ISbit(10) /* Punctuation */
#define _ISalnum  _ISbit(11) /* Alphanumeric */

/* The block */
extern const unsigned short __ctype_b[];
#define __isctype(_C, _TYPE) \
	(__ctype_b[(int)(_C)] & (unsigned short int)(_TYPE))

/* Macros */
#ifndef __NO_CTYPE
# define isalnum(C)  __isctype((C), _ISalpha | _ISdigit)
# define isalpha(C)  __isctype((C), _ISalpha)
# define isascii(C)  ((C) < 0x80)
# define isblank(C)  __isctype((C), _ISblank)
# define iscntrl(C)  __isctype((C), _IScntrl)
# define isdigit(C)  __isctype((C), _ISdigit)
# define isgraph(C)  __isctype((C), _ISgraph)
# define islower(C)  __isctype((C), _ISlower)
# define isprint(C)  __isctype((C), _ISprint)
# define ispunct(C)  __isctype((C), _ISpunct)
# define isspace(C)  __isctype((C), _ISspace)
# define isupper(C)  __isctype((C), _ISupper)
# define isxdigit(C) __isctype((C), _ISxdigit)

# define toascii(C)  ((C) & 0x7F)
#endif

__END_DECLS