diff options
Diffstat (limited to 'newlib/libc/ctype/iswpunct.c')
-rw-r--r-- | newlib/libc/ctype/iswpunct.c | 465 |
1 files changed, 224 insertions, 241 deletions
diff --git a/newlib/libc/ctype/iswpunct.c b/newlib/libc/ctype/iswpunct.c index 1f19b66b8..fc0bd630f 100644 --- a/newlib/libc/ctype/iswpunct.c +++ b/newlib/libc/ctype/iswpunct.c @@ -70,260 +70,243 @@ int _DEFUN(iswpunct,(c), wint_t c) { #ifdef _MB_CAPABLE - int unicode = 0; + unsigned const char *table; + unsigned char *ptr; + unsigned char ctmp; + int size; + wint_t x; if (!strcmp (__locale_charset (), "JIS")) - { - c = __jp2uc (c, JP_JIS); - unicode = 1; - } + c = __jp2uc (c, JP_JIS); else if (!strcmp (__locale_charset (), "SJIS")) - { - c = __jp2uc (c, JP_SJIS); - unicode = 1; - } + c = __jp2uc (c, JP_SJIS); else if (!strcmp (__locale_charset (), "EUCJP")) + c = __jp2uc (c, JP_EUCJP); + + x = (c >> 8); + /* for some large sections, all characters are punctuation so handle them here */ + if ((x >= 0xe0 && x <= 0xf8) || + (x >= 0xf00 && x <= 0xffe) || + (x >= 0x1000 && x <= 0x10fe)) + return 1; + + switch (x) { - c = __jp2uc (c, JP_EUCJP); - unicode = 1; - } - else if (!strcmp (__locale_charset (), "UTF-8")) - { - unicode = 1; + case 0x22: + case 0x25: + case 0x28: + case 0x29: + case 0x2a: + return 1; + case 0x00: + table = u0; + size = sizeof(u0); + break; + case 0x02: + table = u2; + size = sizeof(u2); + break; + case 0x03: + table = u3; + size = sizeof(u3); + break; + case 0x04: + table = u4; + size = sizeof(u4); + break; + case 0x05: + table = u5; + size = sizeof(u5); + break; + case 0x06: + table = u6; + size = sizeof(u6); + break; + case 0x07: + table = u7; + size = sizeof(u7); + break; + case 0x09: + table = u9; + size = sizeof(u9); + break; + case 0x0a: + table = ua; + size = sizeof(ua); + break; + case 0x0b: + table = ub; + size = sizeof(ub); + break; + case 0x0c: + table = uc; + size = sizeof(uc); + break; + case 0x0d: + table = ud; + size = sizeof(ud); + break; + case 0x0e: + table = ue; + size = sizeof(ue); + break; + case 0x0f: + table = uf; + size = sizeof(uf); + break; + case 0x10: + table = u10; + size = sizeof(u10); + break; + case 0x13: + table = u13; + size = sizeof(u13); + break; + case 0x16: + table = u16; + size = sizeof(u16); + break; + case 0x17: + table = u17; + size = sizeof(u17); + break; + case 0x18: + table = u18; + size = sizeof(u18); + break; + case 0x1f: + table = u1f; + size = sizeof(u1f); + break; + case 0x20: + table = u20; + size = sizeof(u20); + break; + case 0x21: + table = u21; + size = sizeof(u21); + break; + case 0x23: + table = u23; + size = sizeof(u23); + break; + case 0x24: + table = u24; + size = sizeof(u24); + break; + case 0x26: + table = u26; + size = sizeof(u26); + break; + case 0x27: + table = u27; + size = sizeof(u27); + break; + case 0x2e: + table = u2e; + size = sizeof(u2e); + break; + case 0x2f: + table = u2f; + size = sizeof(u2f); + break; + case 0x30: + table = u30; + size = sizeof(u30); + break; + case 0x31: + table = u31; + size = sizeof(u31); + break; + case 0x32: + table = u32; + size = sizeof(u32); + break; + case 0x33: + table = u33; + size = sizeof(u33); + break; + case 0xa4: + table = ua4; + size = sizeof(ua4); + break; + case 0xfb: + table = ufb; + size = sizeof(ufb); + break; + case 0xfd: + table = ufd; + size = sizeof(ufd); + break; + case 0xfe: + table = ufe; + size = sizeof(ufe); + break; + case 0xff: + table = uff; + size = sizeof(uff); + break; + case 0x103: + table = u103; + size = sizeof(u103); + break; + case 0x1d0: + table = u1d0; + size = sizeof(u1d0); + break; + case 0x1d1: + table = u1d1; + size = sizeof(u1d1); + break; + case 0x1d6: + table = u1d6; + size = sizeof(u1d6); + break; + case 0x1d7: + table = u1d7; + size = sizeof(u1d7); + break; + case 0xe00: + table = ue00; + size = sizeof(ue00); + break; + case 0xfff: + table = ufff; + size = sizeof(ufff); + break; + case 0x10ff: + table = u10ff; + size = sizeof(u10ff); + break; + default: + return 0; } - - if (unicode) + /* we have narrowed down to a section of 256 characters to check */ + /* now check if c matches the punctuation wide-chars within that section */ + ptr = (unsigned char *)table; + ctmp = (unsigned char)c; + while (ptr < table + size) { - unsigned const char *table; - unsigned char *ptr; - unsigned char ctmp; - int size; - wint_t x = (c >> 8); - - /* for some large sections, all characters are punctuation so handle them here */ - if ((x >= 0xe0 && x <= 0xf8) || - (x >= 0xf00 && x <= 0xffe) || - (x >= 0x1000 && x <= 0x10fe)) + if (ctmp == *ptr) return 1; - - switch (x) - { - case 0x22: - case 0x25: - case 0x28: - case 0x29: - case 0x2a: - return 1; - case 0x00: - table = u0; - size = sizeof(u0); - break; - case 0x02: - table = u2; - size = sizeof(u2); - break; - case 0x03: - table = u3; - size = sizeof(u3); - break; - case 0x04: - table = u4; - size = sizeof(u4); - break; - case 0x05: - table = u5; - size = sizeof(u5); - break; - case 0x06: - table = u6; - size = sizeof(u6); - break; - case 0x07: - table = u7; - size = sizeof(u7); - break; - case 0x09: - table = u9; - size = sizeof(u9); - break; - case 0x0a: - table = ua; - size = sizeof(ua); - break; - case 0x0b: - table = ub; - size = sizeof(ub); - break; - case 0x0c: - table = uc; - size = sizeof(uc); - break; - case 0x0d: - table = ud; - size = sizeof(ud); - break; - case 0x0e: - table = ue; - size = sizeof(ue); - break; - case 0x0f: - table = uf; - size = sizeof(uf); - break; - case 0x10: - table = u10; - size = sizeof(u10); - break; - case 0x13: - table = u13; - size = sizeof(u13); - break; - case 0x16: - table = u16; - size = sizeof(u16); - break; - case 0x17: - table = u17; - size = sizeof(u17); - break; - case 0x18: - table = u18; - size = sizeof(u18); - break; - case 0x1f: - table = u1f; - size = sizeof(u1f); - break; - case 0x20: - table = u20; - size = sizeof(u20); - break; - case 0x21: - table = u21; - size = sizeof(u21); - break; - case 0x23: - table = u23; - size = sizeof(u23); - break; - case 0x24: - table = u24; - size = sizeof(u24); - break; - case 0x26: - table = u26; - size = sizeof(u26); - break; - case 0x27: - table = u27; - size = sizeof(u27); - break; - case 0x2e: - table = u2e; - size = sizeof(u2e); - break; - case 0x2f: - table = u2f; - size = sizeof(u2f); - break; - case 0x30: - table = u30; - size = sizeof(u30); - break; - case 0x31: - table = u31; - size = sizeof(u31); - break; - case 0x32: - table = u32; - size = sizeof(u32); - break; - case 0x33: - table = u33; - size = sizeof(u33); - break; - case 0xa4: - table = ua4; - size = sizeof(ua4); - break; - case 0xfb: - table = ufb; - size = sizeof(ufb); - break; - case 0xfd: - table = ufd; - size = sizeof(ufd); - break; - case 0xfe: - table = ufe; - size = sizeof(ufe); - break; - case 0xff: - table = uff; - size = sizeof(uff); - break; - case 0x103: - table = u103; - size = sizeof(u103); - break; - case 0x1d0: - table = u1d0; - size = sizeof(u1d0); - break; - case 0x1d1: - table = u1d1; - size = sizeof(u1d1); - break; - case 0x1d6: - table = u1d6; - size = sizeof(u1d6); - break; - case 0x1d7: - table = u1d7; - size = sizeof(u1d7); - break; - case 0xe00: - table = ue00; - size = sizeof(ue00); - break; - case 0xfff: - table = ufff; - size = sizeof(ufff); - break; - case 0x10ff: - table = u10ff; - size = sizeof(u10ff); - break; - default: - return 0; - } - /* we have narrowed down to a section of 256 characters to check */ - /* now check if c matches the punctuation wide-chars within that section */ - ptr = (unsigned char *)table; - ctmp = (unsigned char)c; - while (ptr < table + size) + if (ctmp < *ptr) + return 0; + /* otherwise c > *ptr */ + /* look for 0x0 as next element which indicates a range */ + ++ptr; + if (*ptr == 0x0) { - if (ctmp == *ptr) + /* we have a range..see if c falls within range */ + ++ptr; + if (ctmp <= *ptr) return 1; - if (ctmp < *ptr) - return 0; - /* otherwise c > *ptr */ - /* look for 0x0 as next element which indicates a range */ ++ptr; - if (*ptr == 0x0) - { - /* we have a range..see if c falls within range */ - ++ptr; - if (ctmp <= *ptr) - return 1; - ++ptr; - } } - /* not in table */ - return 0; } -#endif /* _MB_CAPABLE */ - + /* not in table */ + return 0; +#else return (c < (wint_t)0x100 ? ispunct (c) : 0); +#endif /* _MB_CAPABLE */ } |