OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [ctype/] [iswalpha.c] - Blame information for rev 207

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

Line No. Rev Author Line
1 207 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
#ifdef _MB_CAPABLE
73
  unsigned const char *table;
74
  unsigned char *ptr;
75
  unsigned char ctmp;
76
  int size;
77
  wint_t x;
78
 
79
  c = _jp2uc (c);
80
 
81
  x = (c >> 8);
82
  /* for some large sections, all characters are alphabetic so handle them here */
83
  if ((x >= 0x34 && x <= 0x4c) ||
84
      (x >= 0x4e && x <= 0x9e) ||
85
      (x >= 0xac && x <= 0xd6) ||
86
      (x >= 0x200 && x <= 0x2a5))
87
    return 1;
88
 
89
  switch (x)
90
    {
91
    case 0x00:
92
      table = u0;
93
      size = sizeof(u0);
94
      break;
95
    case 0x01:
96
    case 0x15:
97
    case 0xa0:
98
    case 0xa1:
99
    case 0xa2:
100
    case 0xa3:
101
    case 0xf9:
102
    case 0xfc:
103
    case 0x2f8:
104
    case 0x2f9:
105
      return 1;
106
    case 0x02:
107
      table = u2;
108
      size = sizeof(u2);
109
      break;
110
    case 0x03:
111
      table = u3;
112
      size = sizeof(u3);
113
      break;
114
    case 0x04:
115
      table = u4;
116
      size = sizeof(u4);
117
      break;
118
    case 0x05:
119
      table = u5;
120
      size = sizeof(u5);
121
      break;
122
    case 0x06:
123
      table = u6;
124
      size = sizeof(u6);
125
      break;
126
    case 0x07:
127
      table = u7;
128
      size = sizeof(u7);
129
      break;
130
    case 0x09:
131
      table = u9;
132
      size = sizeof(u9);
133
      break;
134
    case 0x0a:
135
      table = ua;
136
      size = sizeof(ua);
137
      break;
138
    case 0x0b:
139
      table = ub;
140
      size = sizeof(ub);
141
      break;
142
    case 0x0c:
143
      table = uc;
144
      size = sizeof(uc);
145
      break;
146
    case 0x0d:
147
      table = ud;
148
      size = sizeof(ud);
149
      break;
150
    case 0x0e:
151
      table = ue;
152
      size = sizeof(ue);
153
      break;
154
    case 0x0f:
155
      table = uf;
156
      size = sizeof(uf);
157
      break;
158
    case 0x10:
159
      table = u10;
160
      size = sizeof(u10);
161
      break;
162
    case 0x11:
163
      table = u11;
164
      size = sizeof(u11);
165
      break;
166
    case 0x12:
167
      table = u12;
168
      size = sizeof(u12);
169
      break;
170
    case 0x13:
171
      table = u13;
172
      size = sizeof(u13);
173
      break;
174
    case 0x14:
175
      table = u14;
176
      size = sizeof(u14);
177
      break;
178
    case 0x16:
179
      table = u16;
180
      size = sizeof(u16);
181
      break;
182
    case 0x17:
183
      table = u17;
184
      size = sizeof(u17);
185
      break;
186
    case 0x18:
187
      table = u18;
188
      size = sizeof(u18);
189
      break;
190
    case 0x1e:
191
      table = u1e;
192
      size = sizeof(u1e);
193
      break;
194
    case 0x1f:
195
      table = u1f;
196
      size = sizeof(u1f);
197
      break;
198
    case 0x20:
199
      table = u20;
200
      size = sizeof(u20);
201
      break;
202
    case 0x21:
203
      table = u21;
204
      size = sizeof(u21);
205
      break;
206
    case 0x24:
207
      table = u24;
208
      size = sizeof(u24);
209
      break;
210
    case 0x30:
211
      table = u30;
212
      size = sizeof(u30);
213
      break;
214
    case 0x31:
215
      table = u31;
216
      size = sizeof(u31);
217
      break;
218
    case 0x4d:
219
      table = u4d;
220
      size = sizeof(u4d);
221
      break;
222
    case 0x9f:
223
      table = u9f;
224
      size = sizeof(u9f);
225
      break;
226
    case 0xa4:
227
      table = ua4;
228
      size = sizeof(ua4);
229
      break;
230
    case 0xd7:
231
      table = ud7;
232
      size = sizeof(ud7);
233
      break;
234
    case 0xfa:
235
      table = ufa;
236
      size = sizeof(ufa);
237
      break;
238
    case 0xfb:
239
      table = ufb;
240
      size = sizeof(ufb);
241
      break;
242
    case 0xfd:
243
      table = ufd;
244
      size = sizeof(ufd);
245
      break;
246
    case 0xfe:
247
      table = ufe;
248
      size = sizeof(ufe);
249
      break;
250
    case 0xff:
251
      table = uff;
252
      size = sizeof(uff);
253
      break;
254
    case 0x103:
255
      table = u103;
256
      size = sizeof(u103);
257
      break;
258
    case 0x104:
259
      table = u104;
260
      size = sizeof(u104);
261
      break;
262
    case 0x1d4:
263
      table = u1d4;
264
      size = sizeof(u1d4);
265
      break;
266
    case 0x1d5:
267
      table = u1d5;
268
      size = sizeof(u1d5);
269
      break;
270
    case 0x1d6:
271
      table = u1d6;
272
      size = sizeof(u1d6);
273
      break;
274
    case 0x1d7:
275
      table = u1d7;
276
      size = sizeof(u1d7);
277
      break;
278
    case 0x2a6:
279
      table = u2a6;
280
      size = sizeof(u2a6);
281
      break;
282
    case 0x2fa:
283
      table = u2fa;
284
      size = sizeof(u2fa);
285
      break;
286
    default:
287
      return 0;
288
    }
289
  /* we have narrowed down to a section of 256 characters to check */
290
  /* now check if c matches the alphabetic wide-chars within that section */
291
  ptr = (unsigned char *)table;
292
  ctmp = (unsigned char)c;
293
  while (ptr < table + size)
294
    {
295
      if (ctmp == *ptr)
296
        return 1;
297
      if (ctmp < *ptr)
298
        return 0;
299
      /* otherwise c > *ptr */
300
      /* look for 0x0 as next element which indicates a range */
301
      ++ptr;
302
      if (*ptr == 0x0)
303
        {
304
          /* we have a range..see if c falls within range */
305
          ++ptr;
306
          if (ctmp <= *ptr)
307
            return 1;
308
          ++ptr;
309
        }
310
    }
311
  /* not in table */
312
  return 0;
313
#else
314
  return (c < (wint_t)0x100 ? isalpha (c) : 0);
315
#endif /* _MB_CAPABLE */
316
}
317
 

powered by: WebSVN 2.1.0

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