OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [ctype/] [iswalpha.c] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* 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
/*
31
FUNCTION
32
        <<iswalpha>>---alphabetic wide character test
33
 
34
INDEX
35
        iswalpha
36
 
37
ANSI_SYNOPSIS
38
        #include <wctype.h>
39
        int iswalpha(wint_t <[c]>);
40
 
41
TRAD_SYNOPSIS
42
        #include <wctype.h>
43
        int iswalpha(<[c]>)
44
        wint_t <[c]>;
45
 
46
DESCRIPTION
47
<<iswalpha>> is a function which classifies wide-character values that
48
are alphabetic.
49
 
50
RETURNS
51
<<iswalpha>> returns non-zero if <[c]> is an alphabetic wide character.
52
 
53
PORTABILITY
54
<<iswalpha>> is C99.
55
 
56
No supporting OS subroutines are required.
57
*/
58
#include <_ansi.h>
59
#include <newlib.h>
60
#include <wctype.h>
61
#include <string.h>
62
#include <ctype.h>
63
#include "local.h"
64
 
65
#ifdef _MB_CAPABLE
66
#include "utf8alpha.h"
67
#endif /* _MB_CAPABLE */
68
 
69
int
70
_DEFUN(iswalpha,(c), wint_t c)
71
{
72
  int unicode = 0;
73
  if (__lc_ctype[0] == 'C' && __lc_ctype[1] == '\0')
74
    {
75
      unicode = 0;
76
      /* fall-through */
77
    }
78
#ifdef _MB_CAPABLE
79
  else if (!strcmp (__lc_ctype, "C-JIS"))
80
    {
81
      c = __jp2uc (c, JP_JIS);
82
      unicode = 1;
83
    }
84
  else if (!strcmp (__lc_ctype, "C-SJIS"))
85
    {
86
      c = __jp2uc (c, JP_SJIS);
87
      unicode = 1;
88
    }
89
  else if (!strcmp (__lc_ctype, "C-EUCJP"))
90
    {
91
      c = __jp2uc (c, JP_EUCJP);
92
      unicode = 1;
93
    }
94
  else if (!strcmp (__lc_ctype, "C-UTF-8"))
95
    {
96
      unicode = 1;
97
    }
98
 
99
  if (unicode)
100
    {
101
      unsigned const char *table;
102
      unsigned char *ptr;
103
      unsigned char ctmp;
104
      int size;
105
      wint_t x = (c >> 8);
106
 
107
      /* for some large sections, all characters are alphabetic so handle them here */
108
      if ((x >= 0x34 && x <= 0x4c) ||
109
          (x >= 0x4e && x <= 0x9e) ||
110
          (x >= 0xac && x <= 0xd6) ||
111
          (x >= 0x200 && x <= 0x2a5))
112
        return 1;
113
 
114
      switch (x)
115
        {
116
        case 0x00:
117
          table = u0;
118
          size = sizeof(u0);
119
          break;
120
        case 0x01:
121
        case 0x15:
122
        case 0xa0:
123
        case 0xa1:
124
        case 0xa2:
125
        case 0xa3:
126
        case 0xf9:
127
        case 0xfc:
128
        case 0x2f8:
129
        case 0x2f9:
130
          return 1;
131
        case 0x02:
132
          table = u2;
133
          size = sizeof(u2);
134
          break;
135
        case 0x03:
136
          table = u3;
137
          size = sizeof(u3);
138
          break;
139
        case 0x04:
140
          table = u4;
141
          size = sizeof(u4);
142
          break;
143
        case 0x05:
144
          table = u5;
145
          size = sizeof(u5);
146
          break;
147
        case 0x06:
148
          table = u6;
149
          size = sizeof(u6);
150
          break;
151
        case 0x07:
152
          table = u7;
153
          size = sizeof(u7);
154
          break;
155
        case 0x09:
156
          table = u9;
157
          size = sizeof(u9);
158
          break;
159
        case 0x0a:
160
          table = ua;
161
          size = sizeof(ua);
162
          break;
163
        case 0x0b:
164
          table = ub;
165
          size = sizeof(ub);
166
          break;
167
        case 0x0c:
168
          table = uc;
169
          size = sizeof(uc);
170
          break;
171
        case 0x0d:
172
          table = ud;
173
          size = sizeof(ud);
174
          break;
175
        case 0x0e:
176
          table = ue;
177
          size = sizeof(ue);
178
          break;
179
        case 0x0f:
180
          table = uf;
181
          size = sizeof(uf);
182
          break;
183
        case 0x10:
184
          table = u10;
185
          size = sizeof(u10);
186
          break;
187
        case 0x11:
188
          table = u11;
189
          size = sizeof(u11);
190
          break;
191
        case 0x12:
192
          table = u12;
193
          size = sizeof(u12);
194
          break;
195
        case 0x13:
196
          table = u13;
197
          size = sizeof(u13);
198
          break;
199
        case 0x14:
200
          table = u14;
201
          size = sizeof(u14);
202
          break;
203
        case 0x16:
204
          table = u16;
205
          size = sizeof(u16);
206
          break;
207
        case 0x17:
208
          table = u17;
209
          size = sizeof(u17);
210
          break;
211
        case 0x18:
212
          table = u18;
213
          size = sizeof(u18);
214
          break;
215
        case 0x1e:
216
          table = u1e;
217
          size = sizeof(u1e);
218
          break;
219
        case 0x1f:
220
          table = u1f;
221
          size = sizeof(u1f);
222
          break;
223
        case 0x20:
224
          table = u20;
225
          size = sizeof(u20);
226
          break;
227
        case 0x21:
228
          table = u21;
229
          size = sizeof(u21);
230
          break;
231
        case 0x24:
232
          table = u24;
233
          size = sizeof(u24);
234
          break;
235
        case 0x30:
236
          table = u30;
237
          size = sizeof(u30);
238
          break;
239
        case 0x31:
240
          table = u31;
241
          size = sizeof(u31);
242
          break;
243
        case 0x4d:
244
          table = u4d;
245
          size = sizeof(u4d);
246
          break;
247
        case 0x9f:
248
          table = u9f;
249
          size = sizeof(u9f);
250
          break;
251
        case 0xa4:
252
          table = ua4;
253
          size = sizeof(ua4);
254
          break;
255
        case 0xd7:
256
          table = ud7;
257
          size = sizeof(ud7);
258
          break;
259
        case 0xfa:
260
          table = ufa;
261
          size = sizeof(ufa);
262
          break;
263
        case 0xfb:
264
          table = ufb;
265
          size = sizeof(ufb);
266
          break;
267
        case 0xfd:
268
          table = ufd;
269
          size = sizeof(ufd);
270
          break;
271
        case 0xfe:
272
          table = ufe;
273
          size = sizeof(ufe);
274
          break;
275
        case 0xff:
276
          table = uff;
277
          size = sizeof(uff);
278
          break;
279
        case 0x103:
280
          table = u103;
281
          size = sizeof(u103);
282
          break;
283
        case 0x104:
284
          table = u104;
285
          size = sizeof(u104);
286
          break;
287
        case 0x1d4:
288
          table = u1d4;
289
          size = sizeof(u1d4);
290
          break;
291
        case 0x1d5:
292
          table = u1d5;
293
          size = sizeof(u1d5);
294
          break;
295
        case 0x1d6:
296
          table = u1d6;
297
          size = sizeof(u1d6);
298
          break;
299
        case 0x1d7:
300
          table = u1d7;
301
          size = sizeof(u1d7);
302
          break;
303
        case 0x2a6:
304
          table = u2a6;
305
          size = sizeof(u2a6);
306
          break;
307
        case 0x2fa:
308
          table = u2fa;
309
          size = sizeof(u2fa);
310
          break;
311
        default:
312
          return 0;
313
        }
314
      /* we have narrowed down to a section of 256 characters to check */
315
      /* now check if c matches the alphabetic wide-chars within that section */
316
      ptr = (unsigned char *)table;
317
      ctmp = (unsigned char)c;
318
      while (ptr < table + size)
319
        {
320
          if (ctmp == *ptr)
321
            return 1;
322
          if (ctmp < *ptr)
323
            return 0;
324
          /* otherwise c > *ptr */
325
          /* look for 0x0 as next element which indicates a range */
326
          ++ptr;
327
          if (*ptr == 0x0)
328
            {
329
              /* we have a range..see if c falls within range */
330
              ++ptr;
331
              if (ctmp <= *ptr)
332
                return 1;
333
              ++ptr;
334
            }
335
        }
336
      /* not in table */
337
      return 0;
338
    }
339
#endif /* _MB_CAPABLE */
340
 
341
  return (c < (wint_t)0x100 ? isalpha (c) : 0);
342
}
343
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.