]> git.saurik.com Git - apple/libc.git/blame - include/ctype.h
Libc-262.tar.gz
[apple/libc.git] / include / ctype.h
CommitLineData
5b2abdfb
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1989, 1993
24 * The Regents of the University of California. All rights reserved.
25 * (c) UNIX System Laboratories, Inc.
26 * All or some portions of this file are derived from material licensed
27 * to the University of California by American Telephone and Telegraph
28 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
29 * the permission of UNIX System Laboratories, Inc.
30 *
31 * This code is derived from software contributed to Berkeley by
32 * Paul Borman at Krystal Technologies.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)ctype.h 8.4 (Berkeley) 1/21/94
63 */
64
65#ifndef _CTYPE_H_
66#define _CTYPE_H_
67
68#include <runetype.h>
69
70#define _A 0x00000100L /* Alpha */
71#define _C 0x00000200L /* Control */
72#define _D 0x00000400L /* Digit */
73#define _G 0x00000800L /* Graph */
74#define _L 0x00001000L /* Lower */
75#define _P 0x00002000L /* Punct */
76#define _S 0x00004000L /* Space */
77#define _U 0x00008000L /* Upper */
78#define _X 0x00010000L /* X digit */
79#define _B 0x00020000L /* Blank */
80#define _R 0x00040000L /* Print */
81#define _I 0x00080000L /* Ideogram */
82#define _T 0x00100000L /* Special */
83#define _Q 0x00200000L /* Phonogram */
84
85#define _CTYPE_A _A
86#define _CTYPE_C _C
87#define _CTYPE_D _D
88#define _CTYPE_G _G
89#define _CTYPE_L _L
90#define _CTYPE_P _P
91#define _CTYPE_S _S
92#define _CTYPE_U _U
93#define _CTYPE_X _X
94#define _CTYPE_B _B
95#define _CTYPE_R _R
96#define _CTYPE_I _I
97#define _CTYPE_T _T
98#define _CTYPE_Q _Q
99
100__BEGIN_DECLS
101int isalnum __P((int));
102int isalpha __P((int));
103int iscntrl __P((int));
104int isdigit __P((int));
105int isgraph __P((int));
106int islower __P((int));
107int isprint __P((int));
108int ispunct __P((int));
109int isspace __P((int));
110int isupper __P((int));
111int isxdigit __P((int));
112int tolower __P((int));
113int toupper __P((int));
114
115#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
116int digittoint __P((int));
117int isascii __P((int));
118int isblank __P((int));
119int ishexnumber __P((int));
120int isideogram __P((int));
121int isnumber __P((int));
122int isphonogram __P((int));
123int isrune __P((int));
124int isspecial __P((int));
125int toascii __P((int));
126#endif
127__END_DECLS
128
129
130#define isalnum(c) __istype((c), (_A|_D))
131#define isalpha(c) __istype((c), _A)
132#define iscntrl(c) __istype((c), _C)
133#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */
134#define isgraph(c) __istype((c), _G)
135#define islower(c) __istype((c), _L)
136#define isprint(c) __istype((c), _R)
137#define ispunct(c) __istype((c), _P)
138#define isspace(c) __istype((c), _S)
139#define isupper(c) __istype((c), _U)
140#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */
141#define tolower(c) __tolower(c)
142#define toupper(c) __toupper(c)
143
144#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
145#define digittoint(c) __maskrune((c), 0xFF)
146#define isascii(c) ((c & ~0x7F) == 0)
147#define isblank(c) __istype((c), _B)
148#define ishexnumber(c) __istype((c), _X)
149#define isideogram(c) __istype((c), _I)
150#define isnumber(c) __istype((c), _D)
151#define isphonogram(c) __istype((c), _T)
152#define isrune(c) __istype((c), 0xFFFFFF00L)
153#define isspecial(c) __istype((c), _Q)
154#define toascii(c) ((c) & 0x7F)
155#endif
156
157/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
158__BEGIN_DECLS
159unsigned long ___runetype __P((_BSD_CT_RUNE_T_));
160_BSD_CT_RUNE_T_ ___tolower __P((_BSD_CT_RUNE_T_));
161_BSD_CT_RUNE_T_ ___toupper __P((_BSD_CT_RUNE_T_));
162__END_DECLS
163
164/*
165 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
166 * to generate code for extern versions of all our inline functions.
167 */
168#ifdef _EXTERNALIZE_CTYPE_INLINES_
169#define _USE_CTYPE_INLINE_
170#define static
171#define __inline
172#endif
173
174/*
175 * Use inline functions if we are allowed to and the compiler supports them.
176 */
177#if !defined(_DONT_USE_CTYPE_INLINE_) && \
178 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
179
180static __inline int
181__maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
182{
183 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
184 _CurrentRuneLocale->runetype[_c]) & _f;
185}
186
187static __inline int
188__istype(_BSD_CT_RUNE_T_ c, unsigned long f)
189{
190 return !!(__maskrune(c, f));
191}
192
193static __inline _BSD_CT_RUNE_T_
194__isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
195{
196 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
197 !!(_DefaultRuneLocale.runetype[_c] & _f);
198}
199
200static __inline _BSD_CT_RUNE_T_
201__toupper(_BSD_CT_RUNE_T_ _c)
202{
203 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
204 _CurrentRuneLocale->mapupper[_c];
205}
206
207static __inline _BSD_CT_RUNE_T_
208__tolower(_BSD_CT_RUNE_T_ _c)
209{
210 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
211 _CurrentRuneLocale->maplower[_c];
212}
213
214#else /* not using inlines */
215
216__BEGIN_DECLS
217int __maskrune __P((_BSD_CT_RUNE_T_, unsigned long));
218int __istype __P((_BSD_CT_RUNE_T_, unsigned long));
219int __isctype __P((_BSD_CT_RUNE_T_, unsigned long));
220_BSD_CT_RUNE_T_ __toupper __P((_BSD_CT_RUNE_T_));
221_BSD_CT_RUNE_T_ __tolower __P((_BSD_CT_RUNE_T_));
222__END_DECLS
223#endif /* using inlines */
224
225#endif /* !_CTYPE_H_ */