xref: /freebsd/include/ctype.h (revision 5a1d1441)
12321c474SPedro F. Giffuni /*-
22321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
32321c474SPedro F. Giffuni  *
459deaec5SRodney W. Grimes  * Copyright (c) 1989, 1993
559deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
659deaec5SRodney W. Grimes  * (c) UNIX System Laboratories, Inc.
759deaec5SRodney W. Grimes  * All or some portions of this file are derived from material licensed
859deaec5SRodney W. Grimes  * to the University of California by American Telephone and Telegraph
959deaec5SRodney W. Grimes  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
1059deaec5SRodney W. Grimes  * the permission of UNIX System Laboratories, Inc.
1159deaec5SRodney W. Grimes  *
1259deaec5SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
1359deaec5SRodney W. Grimes  * Paul Borman at Krystal Technologies.
1459deaec5SRodney W. Grimes  *
1559deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
1659deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
1759deaec5SRodney W. Grimes  * are met:
1859deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1959deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
2059deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
2159deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
2259deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
23f2556687SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
2459deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
2559deaec5SRodney W. Grimes  *    without specific prior written permission.
2659deaec5SRodney W. Grimes  *
2759deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2859deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2959deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3059deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3159deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3259deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3359deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3459deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3559deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3659deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3759deaec5SRodney W. Grimes  * SUCH DAMAGE.
3859deaec5SRodney W. Grimes  */
3959deaec5SRodney W. Grimes 
4059deaec5SRodney W. Grimes #ifndef _CTYPE_H_
4159deaec5SRodney W. Grimes #define	_CTYPE_H_
4259deaec5SRodney W. Grimes 
4386eedb4eSMike Barcroft #include <sys/cdefs.h>
4486eedb4eSMike Barcroft #include <sys/_types.h>
4516133e15STim J. Robbins #include <_ctype.h>
4659deaec5SRodney W. Grimes 
4718c34920SBruce Evans __BEGIN_DECLS
48bb28f3c2SWarner Losh int	isalnum(int);
49bb28f3c2SWarner Losh int	isalpha(int);
50bb28f3c2SWarner Losh int	iscntrl(int);
51bb28f3c2SWarner Losh int	isdigit(int);
52bb28f3c2SWarner Losh int	isgraph(int);
53bb28f3c2SWarner Losh int	islower(int);
54bb28f3c2SWarner Losh int	isprint(int);
55bb28f3c2SWarner Losh int	ispunct(int);
56bb28f3c2SWarner Losh int	isspace(int);
57bb28f3c2SWarner Losh int	isupper(int);
58bb28f3c2SWarner Losh int	isxdigit(int);
59bb28f3c2SWarner Losh int	tolower(int);
60bb28f3c2SWarner Losh int	toupper(int);
6118c34920SBruce Evans 
62423eb945SMike Barcroft #if __XSI_VISIBLE
63bb28f3c2SWarner Losh int	isascii(int);
64423eb945SMike Barcroft int	toascii(int);
65423eb945SMike Barcroft #endif
66423eb945SMike Barcroft 
67e2676714STim J. Robbins #if __ISO_C_VISIBLE >= 1999
68e2676714STim J. Robbins int	isblank(int);
69e2676714STim J. Robbins #endif
70e2676714STim J. Robbins 
71423eb945SMike Barcroft #if __BSD_VISIBLE
72423eb945SMike Barcroft int	digittoint(int);
73bb28f3c2SWarner Losh int	ishexnumber(int);
74bb28f3c2SWarner Losh int	isideogram(int);
75bb28f3c2SWarner Losh int	isnumber(int);
76bb28f3c2SWarner Losh int	isphonogram(int);
77bb28f3c2SWarner Losh int	isrune(int);
78bb28f3c2SWarner Losh int	isspecial(int);
7918c34920SBruce Evans #endif
80a8ed63bbSDavid Chisnall 
813ac9d659SDavid Chisnall #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
82a8ed63bbSDavid Chisnall #include <xlocale/_ctype.h>
83a8ed63bbSDavid Chisnall #endif
8418c34920SBruce Evans __END_DECLS
8518c34920SBruce Evans 
86c3b43c58SDavid Chisnall #ifndef __cplusplus
87f5dde016SBaptiste Daroussin #define	isalnum(c)	__sbistype((c), _CTYPE_A|_CTYPE_D|_CTYPE_N)
88367ed4e1SAndrey A. Chernov #define	isalpha(c)	__sbistype((c), _CTYPE_A)
89367ed4e1SAndrey A. Chernov #define	iscntrl(c)	__sbistype((c), _CTYPE_C)
90f5dde016SBaptiste Daroussin #define	isdigit(c)	__sbistype((c), _CTYPE_D)
91367ed4e1SAndrey A. Chernov #define	isgraph(c)	__sbistype((c), _CTYPE_G)
92367ed4e1SAndrey A. Chernov #define	islower(c)	__sbistype((c), _CTYPE_L)
93367ed4e1SAndrey A. Chernov #define	isprint(c)	__sbistype((c), _CTYPE_R)
94367ed4e1SAndrey A. Chernov #define	ispunct(c)	__sbistype((c), _CTYPE_P)
95367ed4e1SAndrey A. Chernov #define	isspace(c)	__sbistype((c), _CTYPE_S)
96367ed4e1SAndrey A. Chernov #define	isupper(c)	__sbistype((c), _CTYPE_U)
97f5dde016SBaptiste Daroussin #define	isxdigit(c)	__sbistype((c), _CTYPE_X)
98367ed4e1SAndrey A. Chernov #define	tolower(c)	__sbtolower(c)
99367ed4e1SAndrey A. Chernov #define	toupper(c)	__sbtoupper(c)
100c3b43c58SDavid Chisnall #endif /* !__cplusplus */
10159deaec5SRodney W. Grimes 
102423eb945SMike Barcroft #if __XSI_VISIBLE
103423eb945SMike Barcroft /*
104423eb945SMike Barcroft  * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
105423eb945SMike Barcroft  * tolower() and toupper() respectively, minus extra checking to ensure that
106423eb945SMike Barcroft  * the argument is a lower or uppercase letter respectively.  We've chosen to
107423eb945SMike Barcroft  * implement these macros with the same error checking as tolower() and
108423eb945SMike Barcroft  * toupper() since this doesn't violate the specification itself, only its
109423eb945SMike Barcroft  * intent.  We purposely leave _tolower() and _toupper() undocumented to
110423eb945SMike Barcroft  * discourage their use.
111423eb945SMike Barcroft  *
112423eb945SMike Barcroft  * XXX isascii() and toascii() should similarly be undocumented.
113423eb945SMike Barcroft  */
114367ed4e1SAndrey A. Chernov #define	_tolower(c)	__sbtolower(c)
115367ed4e1SAndrey A. Chernov #define	_toupper(c)	__sbtoupper(c)
11618c34920SBruce Evans #define	isascii(c)	(((c) & ~0x7F) == 0)
117423eb945SMike Barcroft #define	toascii(c)	((c) & 0x7F)
118423eb945SMike Barcroft #endif
119423eb945SMike Barcroft 
120c3b43c58SDavid Chisnall #if __ISO_C_VISIBLE >= 1999 && !defined(__cplusplus)
121367ed4e1SAndrey A. Chernov #define	isblank(c)	__sbistype((c), _CTYPE_B)
122e2676714STim J. Robbins #endif
123e2676714STim J. Robbins 
124423eb945SMike Barcroft #if __BSD_VISIBLE
125367ed4e1SAndrey A. Chernov #define	digittoint(c)	__sbmaskrune((c), 0xFF)
126367ed4e1SAndrey A. Chernov #define	ishexnumber(c)	__sbistype((c), _CTYPE_X)
127367ed4e1SAndrey A. Chernov #define	isideogram(c)	__sbistype((c), _CTYPE_I)
128f5dde016SBaptiste Daroussin #define	isnumber(c)	__sbistype((c), _CTYPE_D|_CTYPE_N)
129367ed4e1SAndrey A. Chernov #define	isphonogram(c)	__sbistype((c), _CTYPE_Q)
130367ed4e1SAndrey A. Chernov #define	isrune(c)	__sbistype((c), 0xFFFFFF00L)
131367ed4e1SAndrey A. Chernov #define	isspecial(c)	__sbistype((c), _CTYPE_T)
13259deaec5SRodney W. Grimes #endif
13359deaec5SRodney W. Grimes 
13459deaec5SRodney W. Grimes #endif /* !_CTYPE_H_ */
135