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. */
55 extern __const unsigned short int *__ctype_b; /* Characteristics. */
56 extern __const unsigned char *__ctype_tolower; /* Case conversions. */
57 extern __const unsigned char *__ctype_toupper; /* Case conversions. */
59 #define __isctype(c, type) (__ctype_b[c] & (unsigned short int) type)
61 #define __isascii(c) (((c) & (1 << 7)) == 0)
62 #define __toascii(c) ((c) & 0x7f)
64 #define __tolower(c) __ctype_tolower[c]
65 #define __toupper(c) __ctype_toupper[c]
67 /* @ This line MUST be broken! m4 will not change it otherwise. @ */
68 #define __exctype(name) \
69 extern int name __P ((int))
71 /* The following names are all functions:
72 int isCHARACTERISTIC(int c);
73 which return nonzero iff C has CHARACTERISTIC.
74 For the meaning of the characteristic names, see the `enum' above. */
92 /* Return the lowercase version of C. */
93 extern int tolower __P ((int __c));
95 /* Return the uppercase version of C. */
96 extern int toupper __P ((int __c));
99 #if defined(__USE_SVID) || defined(__USE_MISC)
101 /* Return nonzero iff C is in the ASCII set
102 (i.e., is no more than 7 bits wide). */
103 extern int isascii __P ((int __c));
105 /* Return the part of C that is in the ASCII set
106 (i.e., the low-order 7 bits of C). */
107 extern int toascii __P ((int __c));
109 #endif /* Use SVID or use misc. */
112 /* These are the same as `toupper' and and `tolower'. */
113 __exctype (_toupper);
114 __exctype (_tolower);
118 #define isalnum(c) __isctype((c), _ISalnum)
119 #define isalpha(c) __isctype((c), _ISalpha)
120 #define iscntrl(c) __isctype((c), _IScntrl)
121 #define isdigit(c) __isctype((c), _ISdigit)
122 #define islower(c) __isctype((c), _ISlower)
123 #define isgraph(c) __isctype((c), _ISgraph)
124 #define isprint(c) __isctype((c), _ISprint)
125 #define ispunct(c) __isctype((c), _ISpunct)
126 #define isspace(c) __isctype((c), _ISspace)
127 #define isupper(c) __isctype((c), _ISupper)
128 #define isxdigit(c) __isctype((c), _ISxdigit)
131 #define isblank(c) __isctype((c), _ISblank)
138 if ((unsigned char) __c != __c)
141 return __tolower (__c);
147 if ((unsigned char) __c != __c)
150 return __toupper (__c);
154 #if defined(__USE_SVID) || defined(__USE_MISC)
155 #define isascii(c) __isascii(c)
156 #define toascii(c) __toascii(c)
159 #endif /* Not __NO_CTYPE. */