source: trunk/libs/newlib/src/newlib/libc/ctype/iswalpha.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 9.2 KB
Line 
1/* Copyright (c) 2002 Red Hat Incorporated.
2   All rights reserved.
3
4   Redistribution and use in source and binary forms, with or without
5   modification, are permitted provided that the following conditions are met:
6
7     Redistributions of source code must retain the above copyright
8     notice, this list of conditions and the following disclaimer.
9
10     Redistributions in binary form must reproduce the above copyright
11     notice, this list of conditions and the following disclaimer in the
12     documentation and/or other materials provided with the distribution.
13
14     The name of Red Hat Incorporated may not be used to endorse
15     or promote products derived from this software without specific
16     prior written permission.
17
18   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21   ARE DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
22   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS   
27   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30/*
31FUNCTION
32        <<iswalpha>>, <<iswalpha_l>>---alphabetic wide character test
33
34INDEX
35        iswalpha
36
37INDEX
38        iswalpha_l
39
40SYNOPSIS
41        #include <wctype.h>
42        int iswalpha(wint_t <[c]>);
43
44        #include <wctype.h>
45        int iswalpha_l(wint_t <[c]>, locale_t <[locale]>);
46
47DESCRIPTION
48<<iswalpha>> is a function which classifies wide-character values that
49are alphabetic.
50
51<<iswalpha_l>> is like <<iswalpha>> but performs the check based on the
52locale specified by the locale object locale.  If <[locale]> is
53LC_GLOBAL_LOCALE or not a valid locale object, the behaviour is undefined.
54
55RETURNS
56<<iswalpha>>, <<iswalpha_l>> return non-zero if <[c]> is an alphabetic
57wide character.
58
59PORTABILITY
60<<iswalpha>> is C99.
61<<iswalpha_l>> is POSIX-1.2008.
62
63No supporting OS subroutines are required.
64*/
65#include <_ansi.h>
66#include <newlib.h>
67#include <wctype.h>
68#include <string.h>
69#include <ctype.h>
70#include "local.h"
71
72#ifdef _MB_CAPABLE
73#include "utf8alpha.h"
74#endif /* _MB_CAPABLE */
75
76int
77iswalpha (wint_t c)
78{
79#ifdef _MB_CAPABLE
80  unsigned const char *table;
81  unsigned char *ptr;
82  unsigned char ctmp;
83  int size;
84  wint_t x;
85
86  c = _jp2uc (c);
87
88  /* Based on and tested against Unicode 5.2
89     See utf8alpha.h for a description how to fetch the data. */
90  x = (c >> 8);
91  /* for some large sections, all characters are alphabetic so handle them here */
92  if ((x >= 0x34 && x <= 0x4c) ||
93      (x >= 0x4e && x <= 0x9e) ||
94      (x >= 0xac && x <= 0xd6) ||
95      (x >= 0x120 && x <= 0x122) ||
96      (x >= 0x130 && x <= 0x133) ||
97      (x >= 0x200 && x <= 0x2a5) ||
98      (x >= 0x2a7 && x <= 0x2b6))
99    return 1;
100 
101  switch (x)
102    {
103    case 0x00:
104      table = u0;
105      size = sizeof(u0);
106      break;
107    case 0x01:
108    case 0x11:
109    case 0x15:
110    case 0x1e:
111    case 0xa0:
112    case 0xa1:
113    case 0xa2:
114    case 0xa3:
115    case 0xa5:
116    case 0xf9:
117    case 0xfc:
118    case 0x2f8:
119    case 0x2f9:
120      return 1;
121    case 0x02:
122      table = u2;
123      size = sizeof(u2);
124      break;
125    case 0x03:
126      table = u3;
127      size = sizeof(u3);
128      break;
129    case 0x04:
130      table = u4;
131      size = sizeof(u4);
132      break;
133    case 0x05:
134      table = u5;
135      size = sizeof(u5);
136      break;
137    case 0x06:
138      table = u6;
139      size = sizeof(u6);
140      break;
141    case 0x07:
142      table = u7;
143      size = sizeof(u7);
144      break;
145    case 0x08:
146      table = u8;
147      size = sizeof(u8);
148      break;
149    case 0x09:
150      table = u9;
151      size = sizeof(u9);
152      break;
153    case 0x0a:
154      table = ua;
155      size = sizeof(ua);
156      break;
157    case 0x0b:
158      table = ub;
159      size = sizeof(ub);
160      break;
161    case 0x0c:
162      table = uc;
163      size = sizeof(uc);
164      break;
165    case 0x0d:
166      table = ud;
167      size = sizeof(ud);
168      break;
169    case 0x0e:
170      table = ue;
171      size = sizeof(ue);
172      break;
173    case 0x0f:
174      table = uf;
175      size = sizeof(uf);
176      break;
177    case 0x10:
178      table = u10;
179      size = sizeof(u10);
180      break;
181    case 0x12:
182      table = u12;
183      size = sizeof(u12);
184      break;
185    case 0x13:
186      table = u13;
187      size = sizeof(u13);
188      break;
189    case 0x14:
190      table = u14;
191      size = sizeof(u14);
192      break;
193    case 0x16:
194      table = u16;
195      size = sizeof(u16);
196      break;
197    case 0x17:
198      table = u17;
199      size = sizeof(u17);
200      break;
201    case 0x18:
202      table = u18;
203      size = sizeof(u18);
204      break;
205    case 0x19:
206      table = u19;
207      size = sizeof(u19);
208      break;
209    case 0x1a:
210      table = u1a;
211      size = sizeof(u1a);
212      break;
213    case 0x1b:
214      table = u1b;
215      size = sizeof(u1b);
216      break;
217    case 0x1c:
218      table = u1c;
219      size = sizeof(u1c);
220      break;
221    case 0x1d:
222      table = u1d;
223      size = sizeof(u1d);
224      break;
225    case 0x1f:
226      table = u1f;
227      size = sizeof(u1f);
228      break;
229    case 0x20:
230      table = u20;
231      size = sizeof(u20);
232      break;
233    case 0x21:
234      table = u21;
235      size = sizeof(u21);
236      break;
237    case 0x24:
238      table = u24;
239      size = sizeof(u24);
240      break;
241    case 0x2c:
242      table = u2c;
243      size = sizeof(u2c);
244      break;
245    case 0x2d:
246      table = u2d;
247      size = sizeof(u2d);
248      break;
249    case 0x2e:
250      table = u2e;
251      size = sizeof(u2e);
252      break;
253    case 0x30:
254      table = u30;
255      size = sizeof(u30);
256      break;
257    case 0x31:
258      table = u31;
259      size = sizeof(u31);
260      break;
261    case 0x4d:
262      table = u4d;
263      size = sizeof(u4d);
264      break;
265    case 0x9f:
266      table = u9f;
267      size = sizeof(u9f);
268      break;
269    case 0xa4:
270      table = ua4;
271      size = sizeof(ua4);
272      break;
273    case 0xa6:
274      table = ua6;
275      size = sizeof(ua6);
276      break;
277    case 0xa7:
278      table = ua7;
279      size = sizeof(ua7);
280      break;
281    case 0xa8:
282      table = ua8;
283      size = sizeof(ua8);
284      break;
285    case 0xa9:
286      table = ua9;
287      size = sizeof(ua9);
288      break;
289    case 0xaa:
290      table = uaa;
291      size = sizeof(uaa);
292      break;
293    case 0xab:
294      table = uab;
295      size = sizeof(uab);
296      break;
297    case 0xd7:
298      table = ud7;
299      size = sizeof(ud7);
300      break;
301    case 0xfa:
302      table = ufa;
303      size = sizeof(ufa);
304      break;
305    case 0xfb:
306      table = ufb;
307      size = sizeof(ufb);
308      break;
309    case 0xfd:
310      table = ufd;
311      size = sizeof(ufd);
312      break;
313    case 0xfe:
314      table = ufe;
315      size = sizeof(ufe);
316      break;
317    case 0xff:
318      table = uff;
319      size = sizeof(uff);
320      break;
321    case 0x100:
322      table = u100;
323      size = sizeof(u100);
324      break;
325    case 0x101:
326      table = u101;
327      size = sizeof(u101);
328      break;
329    case 0x102:
330      table = u102;
331      size = sizeof(u102);
332      break;
333    case 0x103:
334      table = u103;
335      size = sizeof(u103);
336      break;
337    case 0x104:
338      table = u104;
339      size = sizeof(u104);
340      break;
341    case 0x108:
342      table = u108;
343      size = sizeof(u108);
344      break;
345    case 0x109:
346      table = u109;
347      size = sizeof(u109);
348      break;
349    case 0x10a:
350      table = u10a;
351      size = sizeof(u10a);
352      break;
353    case 0x10b:
354      table = u10b;
355      size = sizeof(u10b);
356      break;
357    case 0x10c:
358      table = u10c;
359      size = sizeof(u10c);
360      break;
361    case 0x110:
362      table = u110;
363      size = sizeof(u110);
364      break;
365    case 0x123:
366      table = u123;
367      size = sizeof(u123);
368      break;
369    case 0x124:
370      table = u124;
371      size = sizeof(u124);
372      break;
373    case 0x134:
374      table = u134;
375      size = sizeof(u134);
376      break;
377    case 0x1d4:
378      table = u1d4;
379      size = sizeof(u1d4);
380      break;
381    case 0x1d5:
382      table = u1d5;
383      size = sizeof(u1d5);
384      break;
385    case 0x1d6:
386      table = u1d6;
387      size = sizeof(u1d6);
388      break;
389    case 0x1d7:
390      table = u1d7;
391      size = sizeof(u1d7);
392      break;
393    case 0x1f1:
394      table = u1f1;
395      size = sizeof(u1f1);
396      break;
397    case 0x2a6:
398      table = u2a6;
399      size = sizeof(u2a6);
400      break;
401    case 0x2b7:
402      table = u2b7;
403      size = sizeof(u2b7);
404      break;
405    case 0x2fa:
406      table = u2fa;
407      size = sizeof(u2fa);
408      break;
409    default:
410      return 0;
411    }
412  /* we have narrowed down to a section of 256 characters to check */
413  /* now check if c matches the alphabetic wide-chars within that section */
414  ptr = (unsigned char *)table;
415  ctmp = (unsigned char)c;
416  while (ptr < table + size)
417    {
418      if (ctmp == *ptr)
419        return 1;
420      if (ctmp < *ptr)
421        return 0;
422      /* otherwise c > *ptr */
423      /* look for 0x0 as next element which indicates a range */
424      ++ptr;
425      if (ptr < table + size - 1 && *ptr == 0x0)
426        {
427          /* we have a range..see if c falls within range */
428          ++ptr;
429          if (ctmp <= *ptr)
430            return 1;
431          ++ptr;
432        }
433    }
434  /* not in table */
435  return 0;
436#else
437  return (c < (wint_t)0x100 ? isalpha (c) : 0);
438#endif /* _MB_CAPABLE */
439}
Note: See TracBrowser for help on using the repository browser.