Wed May 1 09:10:04 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[platform/upstream/glibc.git] / wctype / wctype.h
1 /* Copyright (C) 1996 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 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.
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 Library General Public License for more details.
13
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 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.  */
18
19 /*
20  *      ISO/IEC 9899:1990/Amendment 1:1995 7.15:
21  *      Wide-character classification and mapping utilities  <wctype.h>
22  */
23
24 #ifndef _WCTYPE_H
25
26 #define _WCTYPE_H       1
27 #include <features.h>
28
29
30 __BEGIN_DECLS
31
32 /* FIXME: should this go into <stddef.h>???  */
33 #if 0
34 #define __need_wint_t
35 #include <stddef.h>
36 #else
37 /* Integral type unchanged by default argument promotions that can
38    hold any value corresponding to members of the extended character
39    set, as well as at least one value that does not correspond to any
40    member of the extended character set.  */
41 #ifndef __have_wint_t_defined
42 #define __have_wint_t_defined 1
43 /* This is a hack!!! */
44 typedef unsigned int wint_t;
45 #endif
46 #endif
47
48 /* Scalar type that can hold values which represent locale-specific
49    character mappings.  */
50 typedef const unsigned int *wctrans_t;
51
52 /* Scalar type that can hold values which represent locale-specific
53    character classifications.  */
54 typedef unsigned long int wctype_t;
55
56 /* Constant expression of type `wint_t' whose value does not correspond
57    to any member of the extended character set.  */
58 #ifndef WEOF
59 #define WEOF (0xffffffffu)
60 #endif
61
62 #ifndef _ISbit
63 /* These are all the characteristics of characters.
64    If there get to be more than 16 distinct characteristics,
65    many things must be changed that use `unsigned short int's.
66
67    The characteristics are stored always in network byte order (big
68    endian).  We define the bit value interpretations here dependent on the
69    machine's byte order.  */
70
71 #include <endian.h>
72 #if __BYTE_ORDER == __BIG_ENDIAN
73 #define _ISbit(bit)     (1 << bit)
74 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
75 #define _ISbit(bit)     (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
76 #endif
77
78 enum
79 {
80   _ISupper = _ISbit (0),        /* UPPERCASE.  */
81   _ISlower = _ISbit (1),        /* lowercase.  */
82   _ISalpha = _ISbit (2),        /* Alphabetic.  */
83   _ISdigit = _ISbit (3),        /* Numeric.  */
84   _ISxdigit = _ISbit (4),       /* Hexadecimal numeric.  */
85   _ISspace = _ISbit (5),        /* Whitespace.  */
86   _ISprint = _ISbit (6),        /* Printing.  */
87   _ISgraph = _ISbit (7),        /* Graphical.  */
88   _ISblank = _ISbit (8),        /* Blank (usually SPC and TAB).  */
89   _IScntrl = _ISbit (9),        /* Control character.  */
90   _ISpunct = _ISbit (10),       /* Punctuation.  */
91   _ISalnum = _ISbit (11)        /* Alphanumeric.  */
92 };
93 #endif /* Not _ISbit  */
94
95
96 /*
97  * Wide-character classification functions: 7.15.2.1.
98  */
99
100 /* Test for any wide character for which `iswalpha' or `iswdigit' is
101    true.  */
102 int iswalnum __P ((wint_t __wc));
103
104 /* Test for any wide character for which `iswupper' or 'iswlower' is
105    true, or any wide character that is one of a locale-specific set of
106    wide-characters for which none of `iswcntrl', `iswdigit',
107    `iswpunct', or `iswspace' is true.  */
108 int iswalpha __P ((wint_t __wc));
109
110 /* Test for any control wide character.  */
111 int iswcntrl __P ((wint_t __wc));
112
113 /* Test for any wide character that corresponds to a decimal-digit
114    character.  */
115 int iswdigit __P ((wint_t __wc));
116
117 /* Test for any wide character for which `iswprint' is true and
118    `iswspace' is false.  */
119 int iswgraph __P ((wint_t __wc));
120
121 /* Test for any wide character that corresponds to a lowercase letter
122    or is one of a locale-specific set of wide characters for which
123    none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
124 int iswlower __P ((wint_t __wc));
125
126 /* Test for any printing wide character.  */
127 int iswprint __P ((wint_t __wc));
128
129 /* Test for any printing wide character that is one of a
130    locale-specific et of wide characters for which neither `iswspace'
131    nor `iswalnum' is true.  */
132 int iswpunct __P ((wint_t __wc));
133
134 /* Test for any wide character that corresponds to a locale-specific
135    set of wide characters for which none of `iswalnum', `iswgraph', or
136    `iswpunct' is true.  */
137 int iswspace __P ((wint_t __wc));
138
139 /* Test for any wide character that corresponds to an uppercase letter
140    or is one of a locale-specific set of wide character for which none
141    of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
142 int iswupper __P ((wint_t __wc));
143
144 /* Test for any wide character that corresponds to a hexadecimal-digit
145    character equivalent to that performed be the functions described
146    in the previous subclause.  */
147 int iswxdigit __P ((wint_t __wc));
148
149 /*
150  * Extensible wide-character classification functions: 7.15.2.2.
151  */
152
153 /* Construct value that describes a class of wide characters identified
154    by the string argument PROPERTY.  */
155 wctype_t wctype __P ((__const char *__property));
156
157 /* Determine whether the wide-character WC has the property described by
158    DESC.  */
159 int iswctype __P ((wint_t __wc, wctype_t __desc));
160
161
162 /*
163  * Wide-character case-mapping functions: 7.15.3.1.
164  */
165
166 /* Converts an uppercase letter to the corresponding lowercase letter.  */
167 wint_t towlower __P ((wint_t __wc));
168
169 /* Converts an lowercase letter to the corresponding uppercase letter.  */
170 wint_t towupper __P ((wint_t __wc));
171
172 /*
173  * Extensible wide-character mapping functions: 7.15.3.2.
174  */
175
176 /* Construct value that describes a mapping between wide characters
177    identified by the string argument PROPERTY.  */
178 wctrans_t wctrans __P ((__const char *__property));
179
180 /* Map the wide character WC using the mapping described by DESC.  */
181 wint_t towctrans __P ((wint_t __wc, wctrans_t __desc));
182
183
184
185 #ifndef __NO_WCTYPE
186 #define iswalnum(wc)    iswctype ((wc), _ISalnum)
187 #define iswalpha(wc)    iswctype ((wc), _ISalpha)
188 #define iswcntrl(wc)    iswctype ((wc), _IScntrl)
189 #define iswdigit(wc)    iswctype ((wc), _ISdigit)
190 #define iswlower(wc)    iswctype ((wc), _ISlower)
191 #define iswgraph(wc)    iswctype ((wc), _ISgraph)
192 #define iswprint(wc)    iswctype ((wc), _ISprint)
193 #define iswpunct(wc)    iswctype ((wc), _ISpunct)
194 #define iswspace(wc)    iswctype ((wc), _ISspace)
195 #define iswupper(wc)    iswctype ((wc), _ISupper)
196 #define iswxdigit(wc)   iswctype ((wc), _ISxdigit)
197
198 #ifdef  __USE_GNU
199 #define iswblank(wc)    iswctype ((wc), _ISblank)
200 #endif
201
202 /* Pointer to conversion tables.  */
203 extern __const int *__ctype_tolower; /* Case conversions.  */
204 extern __const int *__ctype_toupper; /* Case conversions.  */
205
206 #define towlower(wc)    towctrans (wc, __ctype_tolower)
207 #define towupper(wc)    towctrans (wc, __ctype_toupper)
208
209 #endif /* Not __NO_WCTYPE.  */
210
211 __END_DECLS
212
213 #endif /* wctype.h  */