1 /* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * ANSI Standard 4.3: CHARACTER HANDLING <ctype.h>
30 /* These are all the characteristics of characters. All the
31 interdependencies (such as that an alphabetic is an uppercase or a
32 lowercase) are here. If there get to be more than
33 (sizeof (unsigned short int) * CHAR_BIT) distinct characteristics,
34 many things must be changed that use `unsigned short int's. */
37 _ISupper = 1 << 0, /* UPPERCASE. */
38 _ISlower = 1 << 1, /* lowercase. */
39 _IScntrl = 1 << 2, /* Control character. */
40 _ISdigit = 1 << 3, /* Numeric. */
41 _ISspace = 1 << 4, /* Whitespace. */
42 _IShex = 1 << 5, /* A - F, a - f. */
43 _ISpunct = 1 << 6, /* Punctuation. */
44 _NOgraph = 1 << 7, /* Printing but nongraphical. */
45 _ISblank = 1 << 8, /* Blank (usually SPC and TAB). */
46 _ISalpha = _ISupper | _ISlower, /* Alphabetic. */
47 _ISalnum = _ISalpha | _ISdigit, /* Alphanumeric. */
48 _ISxdigit = _ISdigit | _IShex, /* Hexadecimal numeric. */
49 _ISgraph = _ISalnum | _ISpunct, /* Graphical. */
50 _ISprint = _ISgraph | _NOgraph /* Printing. */
53 /* These are defined in localeinfo.c.
54 The declarations here must match those in localeinfo.h.
56 These point to the second element ([1]) of arrays of size (UCHAR_MAX + 1).
57 EOF is -1, so [EOF] is the first element of the original array.
58 ANSI requires that the ctype functions work for `unsigned char' values
59 and for EOF. The case conversion arrays are of `short int's rather than
60 `unsigned char's because tolower (EOF) must be EOF, which doesn't fit
61 into an `unsigned char'. */
62 extern __const unsigned short int *__ctype_b; /* Characteristics. */
63 extern __const short int *__ctype_tolower; /* Case conversions. */
64 extern __const short int *__ctype_toupper; /* Case conversions. */
66 #define __isctype(c, type) \
67 ((__ctype_b[(int) (c)] & (unsigned short int) type) != 0)
69 #define __isascii(c) (((c) & (1 << 7)) == 0) /* If high bit is set. */
70 #define __toascii(c) ((c) & 0x7f) /* Mask off high bit. */
72 #define __tolower(c) ((int) __ctype_tolower[(int) (c)])
73 #define __toupper(c) ((int) __ctype_toupper[(int) (c)])
75 #define __exctype(name) extern int name __P ((int))
77 /* The following names are all functions:
78 int isCHARACTERISTIC(int c);
79 which return nonzero iff C has CHARACTERISTIC.
80 For the meaning of the characteristic names, see the `enum' above. */
98 /* Return the lowercase version of C. */
99 extern int tolower __P ((int __c));
101 /* Return the uppercase version of C. */
102 extern int toupper __P ((int __c));
105 #if defined(__USE_SVID) || defined(__USE_MISC)
107 /* Return nonzero iff C is in the ASCII set
108 (i.e., is no more than 7 bits wide). */
109 extern int isascii __P ((int __c));
111 /* Return the part of C that is in the ASCII set
112 (i.e., the low-order 7 bits of C). */
113 extern int toascii __P ((int __c));
115 #endif /* Use SVID or use misc. */
118 /* These are the same as `toupper' and and `tolower'. */
119 __exctype (_toupper);
120 __exctype (_tolower);
124 #define isalnum(c) __isctype((c), _ISalnum)
125 #define isalpha(c) __isctype((c), _ISalpha)
126 #define iscntrl(c) __isctype((c), _IScntrl)
127 #define isdigit(c) __isctype((c), _ISdigit)
128 #define islower(c) __isctype((c), _ISlower)
129 #define isgraph(c) __isctype((c), _ISgraph)
130 #define isprint(c) __isctype((c), _ISprint)
131 #define ispunct(c) __isctype((c), _ISpunct)
132 #define isspace(c) __isctype((c), _ISspace)
133 #define isupper(c) __isctype((c), _ISupper)
134 #define isxdigit(c) __isctype((c), _ISxdigit)
137 #define isblank(c) __isctype((c), _ISblank)
140 #define tolower(c) __tolower(c)
141 #define toupper(c) __toupper(c)
143 #if defined(__USE_SVID) || defined(__USE_MISC)
144 #define isascii(c) __isascii(c)
145 #define toascii(c) __toascii(c)
148 #endif /* Not __NO_CTYPE. */