Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/regex/regex2.h
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Structures for [] character-set representation. | * Structures for [] character-set representation. | ||||
*/ | */ | ||||
typedef struct { | typedef struct { | ||||
wint_t min; | wint_t min; | ||||
wint_t max; | wint_t max; | ||||
} crange; | } crange; | ||||
typedef struct { | typedef struct { | ||||
unsigned char bmp[NC / 8]; | unsigned char bmp[NC_MAX / 8]; | ||||
wctype_t *types; | wctype_t *types; | ||||
unsigned int ntypes; | unsigned int ntypes; | ||||
wint_t *wides; | wint_t *wides; | ||||
unsigned int nwides; | unsigned int nwides; | ||||
crange *ranges; | crange *ranges; | ||||
unsigned int nranges; | unsigned int nranges; | ||||
int invert; | int invert; | ||||
int icase; | int icase; | ||||
} cset; | } cset; | ||||
static int | static int | ||||
CHIN1(cset *cs, wint_t ch) | CHIN1(cset *cs, wint_t ch) | ||||
{ | { | ||||
unsigned int i; | unsigned int i; | ||||
assert(ch >= 0); | assert(ch >= 0); | ||||
if (ch < NC) | if (ch < NC) | ||||
return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^ | return (((cs->bmp[ch >> 3] & (1 << (ch & 7))) != 0) ^ | ||||
cs->invert); | cs->invert); | ||||
for (i = 0; i < cs->nwides; i++) | for (i = 0; i < cs->nwides; i++) { | ||||
if (ch == cs->wides[i]) | if (cs->icase) { | ||||
if (ch == towlower(cs->wides[i]) || | |||||
ch == towupper(cs->wides[i])) | |||||
return (!cs->invert); | return (!cs->invert); | ||||
} else if (ch == cs->wides[i]) | |||||
return (!cs->invert); | |||||
} | |||||
for (i = 0; i < cs->nranges; i++) | for (i = 0; i < cs->nranges; i++) | ||||
if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max) | if (cs->ranges[i].min <= ch && ch <= cs->ranges[i].max) | ||||
return (!cs->invert); | return (!cs->invert); | ||||
for (i = 0; i < cs->ntypes; i++) | for (i = 0; i < cs->ntypes; i++) | ||||
if (iswctype(ch, cs->types[i])) | if (iswctype(ch, cs->types[i])) | ||||
return (!cs->invert); | return (!cs->invert); | ||||
return (cs->invert); | return (cs->invert); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |