1/* Copyright (C) 1991,92,93,95,96,97,98,99,2001 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 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 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, write to the Free 16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17 02111-1307 USA. */ 18 19/* 20 * ISO C99 Standard 7.4: Character handling <ctype.h> 21 */ 22 23#ifndef _CTYPE_H 24#define _CTYPE_H 1 25 26#include <features.h> 27#include <bits/types.h> 28 29__BEGIN_DECLS 30 31#ifndef _ISbit 32/* These are all the characteristics of characters. 33 If there get to be more than 16 distinct characteristics, 34 many things must be changed that use `unsigned short int's. 35 36 The characteristics are stored always in network byte order (big 37 endian). We define the bit value interpretations here dependent on the 38 machine's byte order. */ 39 40# include <endian.h> 41# if __BYTE_ORDER == __BIG_ENDIAN 42# define _ISbit(bit) (1 << (bit)) 43# else /* __BYTE_ORDER == __LITTLE_ENDIAN */ 44# define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8)) 45# endif 46 47enum 48{ 49 _ISupper = _ISbit (0), /* UPPERCASE. */ 50 _ISlower = _ISbit (1), /* lowercase. */ 51 _ISalpha = _ISbit (2), /* Alphabetic. */ 52 _ISdigit = _ISbit (3), /* Numeric. */ 53 _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */ 54 _ISspace = _ISbit (5), /* Whitespace. */ 55 _ISprint = _ISbit (6), /* Printing. */ 56 _ISgraph = _ISbit (7), /* Graphical. */ 57 _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */ 58 _IScntrl = _ISbit (9), /* Control character. */ 59 _ISpunct = _ISbit (10), /* Punctuation. */ 60 _ISalnum = _ISbit (11) /* Alphanumeric. */ 61}; 62#endif /* ! _ISbit */ 63 64/* These are defined in ctype-info.c. 65 The declarations here must match those in localeinfo.h. 66 67 In the thread-specific locale model (see `uselocale' in <locale.h>) 68 we cannot use global variables for these as was done in the past. 69 Instead, the following accessor functions return the address of 70 each variable, which is local to the current thread if multithreaded. 71 72 These point into arrays of 384, so they can be indexed by any `unsigned 73 char' value [0,255]; by EOF (-1); or by any `signed char' value 74 [-128,-1). ISO C requires that the ctype functions work for `unsigned 75 char' values and for EOF; we also support negative `signed char' values 76 for broken old programs. The case conversion arrays are of `int's 77 rather than `unsigned char's because tolower (EOF) must be EOF, which 78 doesn't fit into an `unsigned char'. But today more important is that 79 the arrays are also used for multi-byte character sets. */ 80extern __const unsigned short int **__ctype_b_loc (void); /* Characteristics. */ 81extern __const __int32_t **__ctype_tolower_loc (void); /* Case conversions. */ 82extern __const __int32_t **__ctype_toupper_loc (void); /* Case conversions. */ 83 84#define __isctype(c, type) \ 85 ((*__ctype_b_loc())[(int) (c)] & (unsigned short int) type) 86 87#define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */ 88#define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */ 89 90#define __exctype(name) extern int name (int) __THROW 91 92/* The following names are all functions: 93 int isCHARACTERISTIC(int c); 94 which return nonzero iff C has CHARACTERISTIC. 95 For the meaning of the characteristic names, see the `enum' above. */ 96__exctype (isalnum); 97__exctype (isalpha); 98__exctype (iscntrl); 99__exctype (isdigit); 100__exctype (islower); 101__exctype (isgraph); 102__exctype (isprint); 103__exctype (ispunct); 104__exctype (isspace); 105__exctype (isupper); 106__exctype (isxdigit); 107 108#ifdef __USE_ISOC99 109__exctype (isblank); 110#endif 111 112 113/* Return the lowercase version of C. */ 114extern int tolower (int __c) __THROW; 115 116/* Return the uppercase version of C. */ 117extern int toupper (int __c) __THROW; 118 119 120#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN 121 122/* Return nonzero iff C is in the ASCII set 123 (i.e., is no more than 7 bits wide). */ 124extern int isascii (int __c) __THROW; 125 126/* Return the part of C that is in the ASCII set 127 (i.e., the low-order 7 bits of C). */ 128extern int toascii (int __c) __THROW; 129 130/* These are the same as `toupper' and `tolower' except that they do not 131 check the argument for being in the range of a `char'. */ 132__exctype (_toupper); 133__exctype (_tolower); 134#endif /* Use SVID or use misc. */ 135 136/* This code is needed for the optimized mapping functions. */ 137#define __tobody(c, f, a, args) \ 138 (__extension__ \ 139 ({ int __res; \ 140 if (sizeof (c) > 1) \ 141 { \ 142 if (__builtin_constant_p (c)) \ 143 { \ 144 int __c = (c); \ 145 __res = __c < -128 || __c > 255 ? __c : a[__c]; \ 146 } \ 147 else \ 148 __res = f args; \ 149 } \ 150 else \ 151 __res = a[(int) (c)]; \ 152 __res; })) 153 154#ifndef __NO_CTYPE 155# define isalnum(c) __isctype((c), _ISalnum) 156# define isalpha(c) __isctype((c), _ISalpha) 157# define iscntrl(c) __isctype((c), _IScntrl) 158# define isdigit(c) __isctype((c), _ISdigit) 159# define islower(c) __isctype((c), _ISlower) 160# define isgraph(c) __isctype((c), _ISgraph) 161# define isprint(c) __isctype((c), _ISprint) 162# define ispunct(c) __isctype((c), _ISpunct) 163# define isspace(c) __isctype((c), _ISspace) 164# define isupper(c) __isctype((c), _ISupper) 165# define isxdigit(c) __isctype((c), _ISxdigit) 166 167# ifdef __USE_ISOC99 168# define isblank(c) __isctype((c), _ISblank) 169# endif 170 171# ifdef __USE_EXTERN_INLINES 172__extern_inline int 173tolower (int __c) __THROW 174{ 175 return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc())[__c] : __c; 176} 177 178__extern_inline int 179toupper (int __c) __THROW 180{ 181 return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc())[__c] : __c; 182} 183# endif 184 185# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus 186# define tolower(c) __tobody (c, tolower, (*__ctype_tolower_loc()), (c)) 187# define toupper(c) __tobody (c, toupper, (*__ctype_toupper_loc()), (c)) 188# endif /* Optimizing gcc */ 189 190# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN 191# define isascii(c) __isascii (c) 192# define toascii(c) __toascii (c) 193 194# define _tolower(c) ((int) (*__ctype_tolower_loc())[(int) (c)]) 195# define _toupper(c) ((int) (*__ctype_toupper_loc())[(int) (c)]) 196# endif 197 198#endif /* Not __NO_CTYPE. */ 199 200__END_DECLS 201 202#endif /* ctype.h */ 203