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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [ctype/] [iswpunct.c] - Blame information for rev 842

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
        <<iswpunct>>---punctuation wide character test
33
 
34
INDEX
35
        iswpunct
36
 
37
ANSI_SYNOPSIS
38
        #include <wctype.h>
39
        int iswpunct(wint_t <[c]>);
40
 
41
TRAD_SYNOPSIS
42
        #include <wctype.h>
43
        int iswpunct(<[c]>)
44
        wint_t <[c]>;
45
 
46
DESCRIPTION
47
<<iswpunct>> is a function which classifies wide-character values that
48
are punctuation.
49
 
50
RETURNS
51
<<iswpunct>> returns non-zero if <[c]> is a punctuation wide character.
52
 
53
PORTABILITY
54
<<iswpunct>> 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 "utf8punct.h"
67
#endif /* _MB_CAPABLE */
68
 
69
int
70
_DEFUN(iswpunct,(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 punctuation so handle them here */
108
      if ((x >= 0xe0 && x <= 0xf8) ||
109
          (x >= 0xf00 && x <= 0xffe) ||
110
          (x >= 0x1000 && x <= 0x10fe))
111
        return 1;
112
 
113
      switch (x)
114
        {
115
        case 0x22:
116
        case 0x25:
117
        case 0x28:
118
        case 0x29:
119
        case 0x2a:
120
          return 1;
121
        case 0x00:
122
          table = u0;
123
          size = sizeof(u0);
124
          break;
125
        case 0x02:
126
          table = u2;
127
          size = sizeof(u2);
128
          break;
129
        case 0x03:
130
          table = u3;
131
          size = sizeof(u3);
132
          break;
133
        case 0x04:
134
          table = u4;
135
          size = sizeof(u4);
136
          break;
137
        case 0x05:
138
          table = u5;
139
          size = sizeof(u5);
140
          break;
141
        case 0x06:
142
          table = u6;
143
          size = sizeof(u6);
144
          break;
145
        case 0x07:
146
          table = u7;
147
          size = sizeof(u7);
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 0x13:
182
          table = u13;
183
          size = sizeof(u13);
184
          break;
185
        case 0x16:
186
          table = u16;
187
          size = sizeof(u16);
188
          break;
189
        case 0x17:
190
          table = u17;
191
          size = sizeof(u17);
192
          break;
193
        case 0x18:
194
          table = u18;
195
          size = sizeof(u18);
196
          break;
197
        case 0x1f:
198
          table = u1f;
199
          size = sizeof(u1f);
200
          break;
201
        case 0x20:
202
          table = u20;
203
          size = sizeof(u20);
204
          break;
205
        case 0x21:
206
          table = u21;
207
          size = sizeof(u21);
208
          break;
209
        case 0x23:
210
          table = u23;
211
          size = sizeof(u23);
212
          break;
213
        case 0x24:
214
          table = u24;
215
          size = sizeof(u24);
216
          break;
217
        case 0x26:
218
          table = u26;
219
          size = sizeof(u26);
220
          break;
221
        case 0x27:
222
          table = u27;
223
          size = sizeof(u27);
224
          break;
225
        case 0x2e:
226
          table = u2e;
227
          size = sizeof(u2e);
228
          break;
229
        case 0x2f:
230
          table = u2f;
231
          size = sizeof(u2f);
232
          break;
233
        case 0x30:
234
          table = u30;
235
          size = sizeof(u30);
236
          break;
237
        case 0x31:
238
          table = u31;
239
          size = sizeof(u31);
240
          break;
241
        case 0x32:
242
          table = u32;
243
          size = sizeof(u32);
244
          break;
245
        case 0x33:
246
          table = u33;
247
          size = sizeof(u33);
248
          break;
249
        case 0xa4:
250
          table = ua4;
251
          size = sizeof(ua4);
252
          break;
253
        case 0xfb:
254
          table = ufb;
255
          size = sizeof(ufb);
256
          break;
257
        case 0xfd:
258
          table = ufd;
259
          size = sizeof(ufd);
260
          break;
261
        case 0xfe:
262
          table = ufe;
263
          size = sizeof(ufe);
264
          break;
265
        case 0xff:
266
          table = uff;
267
          size = sizeof(uff);
268
          break;
269
        case 0x103:
270
          table = u103;
271
          size = sizeof(u103);
272
          break;
273
        case 0x1d0:
274
          table = u1d0;
275
          size = sizeof(u1d0);
276
          break;
277
        case 0x1d1:
278
          table = u1d1;
279
          size = sizeof(u1d1);
280
          break;
281
        case 0x1d6:
282
          table = u1d6;
283
          size = sizeof(u1d6);
284
          break;
285
        case 0x1d7:
286
          table = u1d7;
287
          size = sizeof(u1d7);
288
          break;
289
        case 0xe00:
290
          table = ue00;
291
          size = sizeof(ue00);
292
          break;
293
        case 0xfff:
294
          table = ufff;
295
          size = sizeof(ufff);
296
          break;
297
        case 0x10ff:
298
          table = u10ff;
299
          size = sizeof(u10ff);
300
          break;
301
        default:
302
          return 0;
303
        }
304
      /* we have narrowed down to a section of 256 characters to check */
305
      /* now check if c matches the punctuation wide-chars within that section */
306
      ptr = (unsigned char *)table;
307
      ctmp = (unsigned char)c;
308
      while (ptr < table + size)
309
        {
310
          if (ctmp == *ptr)
311
            return 1;
312
          if (ctmp < *ptr)
313
            return 0;
314
          /* otherwise c > *ptr */
315
          /* look for 0x0 as next element which indicates a range */
316
          ++ptr;
317
          if (*ptr == 0x0)
318
            {
319
              /* we have a range..see if c falls within range */
320
              ++ptr;
321
              if (ctmp <= *ptr)
322
                return 1;
323
              ++ptr;
324
            }
325
        }
326
      /* not in table */
327
      return 0;
328
    }
329
#endif /* _MB_CAPABLE */
330
 
331
  return (c < (wint_t)0x100 ? ispunct (c) : 0);
332
}
333
 

powered by: WebSVN 2.1.0

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