| 6 |
and semantics are as close as possible to those of the Perl 5 language. |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
| 8 |
Written by Philip Hazel |
Written by Philip Hazel |
| 9 |
Copyright (c) 1997-2005 University of Cambridge |
Copyright (c) 1997-2006 University of Cambridge |
| 10 |
|
|
| 11 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 12 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 86 |
|
|
| 87 |
for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i); |
for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i); |
| 88 |
|
|
| 89 |
/* Then the character class tables. Don't try to be clever and save effort |
/* Then the character class tables. Don't try to be clever and save effort on |
| 90 |
on exclusive ones - in some locales things may be different. Note that the |
exclusive ones - in some locales things may be different. Note that the table |
| 91 |
table for "space" includes everything "isspace" gives, including VT in the |
for "space" includes everything "isspace" gives, including VT in the default |
| 92 |
default locale. This makes it work for the POSIX class [:space:]. */ |
locale. This makes it work for the POSIX class [:space:]. Note also that it is |
| 93 |
|
possible for a character to be alnum or alpha without being lower or upper, |
| 94 |
|
such as "male and female ordinals" (\xAA and \xBA) in the fr_FR locale (at |
| 95 |
|
least under Debian Linux's locales as of 12/2005). So we must test for alnum |
| 96 |
|
specially. */ |
| 97 |
|
|
| 98 |
memset(p, 0, cbit_length); |
memset(p, 0, cbit_length); |
| 99 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
| 100 |
{ |
{ |
| 101 |
if (isdigit(i)) |
if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7); |
| 102 |
{ |
if (isupper(i)) p[cbit_upper + i/8] |= 1 << (i&7); |
| 103 |
p[cbit_digit + i/8] |= 1 << (i&7); |
if (islower(i)) p[cbit_lower + i/8] |= 1 << (i&7); |
| 104 |
p[cbit_word + i/8] |= 1 << (i&7); |
if (isalnum(i)) p[cbit_word + i/8] |= 1 << (i&7); |
|
} |
|
|
if (isupper(i)) |
|
|
{ |
|
|
p[cbit_upper + i/8] |= 1 << (i&7); |
|
|
p[cbit_word + i/8] |= 1 << (i&7); |
|
|
} |
|
|
if (islower(i)) |
|
|
{ |
|
|
p[cbit_lower + i/8] |= 1 << (i&7); |
|
|
p[cbit_word + i/8] |= 1 << (i&7); |
|
|
} |
|
| 105 |
if (i == '_') p[cbit_word + i/8] |= 1 << (i&7); |
if (i == '_') p[cbit_word + i/8] |= 1 << (i&7); |
| 106 |
if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7); |
if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7); |
| 107 |
if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7); |
if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7); |