| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef VMUNI_H |
| 21 |
#define VMUNI_H |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include "wchar.h" |
| 25 |
#include "t3std.h" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
int t3_is_lower(wchar_t ch); |
| 36 |
int t3_is_upper(wchar_t ch); |
| 37 |
int t3_is_title(wchar_t ch); |
| 38 |
const wchar_t *t3_to_lower(wchar_t ch); |
| 39 |
const wchar_t *t3_to_upper(wchar_t ch); |
| 40 |
const wchar_t *t3_to_title(wchar_t ch); |
| 41 |
const wchar_t *t3_to_fold(wchar_t ch); |
| 42 |
wchar_t t3_simple_case_fold(wchar_t ch); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#define T3_CTYPE_UNDEF 0 |
| 49 |
#define T3_CTYPE_ALPHA 1 |
| 50 |
#define T3_CTYPE_UPPER 2 |
| 51 |
#define T3_CTYPE_TITLE 3 |
| 52 |
#define T3_CTYPE_LOWER 4 |
| 53 |
#define T3_CTYPE_DIGIT 5 |
| 54 |
#define T3_CTYPE_SPACE 6 |
| 55 |
#define T3_CTYPE_VSPAC 7 |
| 56 |
#define T3_CTYPE_PUNCT 8 |
| 57 |
#define T3_CTYPE_OTHER 9 |
| 58 |
|
| 59 |
|
| 60 |
#define T3_CTYPE_NAMES \ |
| 61 |
"T3_CTYPE_UNDEF", "T3_CTYPE_ALPHA", "T3_CTYPE_UPPER", "T3_CTYPE_TITLE", \ |
| 62 |
"T3_CTYPE_LOWER", "T3_CTYPE_DIGIT", "T3_CTYPE_SPACE", "T3_CTYPE_VSPAC", \ |
| 63 |
"T3_CTYPE_PUNCT", "T3_CTYPE_OTHER" |
| 64 |
|
| 65 |
|
| 66 |
int t3_get_chartype(wchar_t ch); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
inline int t3_is_alpha(wchar_t ch) |
| 74 |
{ |
| 75 |
int ctype = t3_get_chartype(ch); |
| 76 |
return (ctype >= T3_CTYPE_ALPHA && ctype <= T3_CTYPE_LOWER); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
inline int t3_is_upper(wchar_t ch) |
| 81 |
{ |
| 82 |
int ctype = t3_get_chartype(ch); |
| 83 |
return (ctype == T3_CTYPE_UPPER || ctype == T3_CTYPE_TITLE); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
inline int t3_is_lower(wchar_t ch) |
| 88 |
{ |
| 89 |
return (t3_get_chartype(ch) == T3_CTYPE_LOWER); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
inline int t3_is_digit(wchar_t ch) |
| 94 |
{ |
| 95 |
return (t3_get_chartype(ch) == T3_CTYPE_DIGIT); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
inline int t3_is_space(wchar_t ch) |
| 100 |
{ |
| 101 |
return (t3_get_chartype(ch) == T3_CTYPE_SPACE); |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
inline int t3_is_vspace(wchar_t ch) |
| 106 |
{ |
| 107 |
return (t3_get_chartype(ch) == T3_CTYPE_VSPAC); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
inline int t3_is_whitespace(wchar_t ch) |
| 112 |
{ |
| 113 |
int t = t3_get_chartype(ch); |
| 114 |
return (t == T3_CTYPE_SPACE || t == T3_CTYPE_VSPAC); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
inline int t3_is_punct(wchar_t ch) |
| 119 |
{ |
| 120 |
return (t3_get_chartype(ch) == T3_CTYPE_PUNCT); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
inline int t3_is_unichar(wchar_t ch) |
| 125 |
{ |
| 126 |
return (t3_get_chartype(ch) != T3_CTYPE_UNDEF); |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
class CVmCaseFoldStr |
| 134 |
{ |
| 135 |
public: |
| 136 |
CVmCaseFoldStr(const wchar_t *s) { init(s, wcslen(s)); } |
| 137 |
CVmCaseFoldStr(const wchar_t *s, size_t len) { init(s, len); } |
| 138 |
|
| 139 |
|
| 140 |
const wchar_t *getptr() const { return p; } |
| 141 |
|
| 142 |
|
| 143 |
int more() const { return rem != 0 || *fp != 0 || fp == ie; } |
| 144 |
|
| 145 |
|
| 146 |
int at_boundary() const { return fp != fpbase && *fp == 0; } |
| 147 |
|
| 148 |
|
| 149 |
wchar_t getch() |
| 150 |
{ |
| 151 |
|
| 152 |
if (fp != ie && *fp == 0) |
| 153 |
{ |
| 154 |
|
| 155 |
if (rem == 0) |
| 156 |
return 0; |
| 157 |
|
| 158 |
|
| 159 |
wchar_t ch = *p++; |
| 160 |
--rem; |
| 161 |
|
| 162 |
|
| 163 |
if ((fp = t3_to_fold(ch)) == 0) |
| 164 |
{ |
| 165 |
ie[0] = ch; |
| 166 |
fpbase = fp = ie; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
return *fp++; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
static int wstreq(const wchar_t *a, const wchar_t *b) |
| 179 |
{ |
| 180 |
|
| 181 |
for (CVmCaseFoldStr fa(a), fb(b) ; ; ) |
| 182 |
{ |
| 183 |
|
| 184 |
wchar_t ca = fa.getch(); |
| 185 |
wchar_t cb = fb.getch(); |
| 186 |
|
| 187 |
|
| 188 |
if (ca != cb) |
| 189 |
return FALSE; |
| 190 |
|
| 191 |
|
| 192 |
if (ca == 0) |
| 193 |
return TRUE; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
private: |
| 198 |
void init(const wchar_t *s, size_t len) |
| 199 |
{ |
| 200 |
|
| 201 |
this->p = s; |
| 202 |
this->rem = len; |
| 203 |
|
| 204 |
|
| 205 |
ie[1] = 0; |
| 206 |
|
| 207 |
|
| 208 |
fpbase = ie; |
| 209 |
fp = &ie[1]; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
const wchar_t *fp; |
| 214 |
|
| 215 |
|
| 216 |
const wchar_t *fpbase; |
| 217 |
|
| 218 |
|
| 219 |
wchar_t ie[2]; |
| 220 |
|
| 221 |
|
| 222 |
const wchar_t *p; |
| 223 |
size_t rem; |
| 224 |
}; |
| 225 |
|
| 226 |
#endif |
| 227 |
|