[279] | 1 | /**********************************************************************
|
---|
| 2 | unicode.c - Oniguruma (regular expression library)
|
---|
| 3 | **********************************************************************/
|
---|
| 4 | /*-
|
---|
| 5 | * Copyright (c) 2002-2013 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
---|
| 6 | * All rights reserved.
|
---|
| 7 | *
|
---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
---|
| 9 | * modification, are permitted provided that the following conditions
|
---|
| 10 | * are met:
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 27 | * SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #include "regint.h"
|
---|
| 31 |
|
---|
| 32 | #define ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(code,ctype) \
|
---|
| 33 | ((EncUNICODE_ISO_8859_1_CtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
|
---|
| 34 | #if 0
|
---|
| 35 | #define ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(code,cbit) \
|
---|
| 36 | ((EncUNICODE_ISO_8859_1_CtypeTable[code] & (cbit)) != 0)
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
| 39 | static const unsigned short EncUNICODE_ISO_8859_1_CtypeTable[256] = {
|
---|
| 40 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
---|
| 41 | 0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,
|
---|
| 42 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
---|
| 43 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
|
---|
| 44 | 0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
---|
| 45 | 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
---|
| 46 | 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0,
|
---|
| 47 | 0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
|
---|
| 48 | 0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2,
|
---|
| 49 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
|
---|
| 50 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
|
---|
| 51 | 0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0,
|
---|
| 52 | 0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2,
|
---|
| 53 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
|
---|
| 54 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
|
---|
| 55 | 0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008,
|
---|
| 56 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0288, 0x0008, 0x0008,
|
---|
| 57 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
---|
| 58 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
---|
| 59 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
|
---|
| 60 | 0x0284, 0x01a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
|
---|
| 61 | 0x00a0, 0x00a0, 0x30e2, 0x01a0, 0x00a0, 0x00a8, 0x00a0, 0x00a0,
|
---|
| 62 | 0x00a0, 0x00a0, 0x10a0, 0x10a0, 0x00a0, 0x30e2, 0x00a0, 0x01a0,
|
---|
| 63 | 0x00a0, 0x10a0, 0x30e2, 0x01a0, 0x10a0, 0x10a0, 0x10a0, 0x01a0,
|
---|
| 64 | 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
|
---|
| 65 | 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2,
|
---|
| 66 | 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x00a0,
|
---|
| 67 | 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x34a2, 0x30e2,
|
---|
| 68 | 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
|
---|
| 69 | 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2,
|
---|
| 70 | 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x00a0,
|
---|
| 71 | 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2, 0x30e2
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | typedef struct {
|
---|
| 75 | int n;
|
---|
| 76 | OnigCodePoint code[3];
|
---|
| 77 | } CodePointList3;
|
---|
| 78 |
|
---|
| 79 | typedef struct {
|
---|
| 80 | OnigCodePoint from;
|
---|
| 81 | CodePointList3 to;
|
---|
| 82 | } CaseFold_11_Type;
|
---|
| 83 |
|
---|
| 84 | typedef struct {
|
---|
| 85 | OnigCodePoint from;
|
---|
| 86 | CodePointList3 to;
|
---|
| 87 | } CaseUnfold_11_Type;
|
---|
| 88 |
|
---|
| 89 | typedef struct {
|
---|
| 90 | int n;
|
---|
| 91 | OnigCodePoint code[2];
|
---|
| 92 | } CodePointList2;
|
---|
| 93 |
|
---|
| 94 | typedef struct {
|
---|
| 95 | OnigCodePoint from[2];
|
---|
| 96 | CodePointList2 to;
|
---|
| 97 | } CaseUnfold_12_Type;
|
---|
| 98 |
|
---|
| 99 | typedef struct {
|
---|
| 100 | OnigCodePoint from[3];
|
---|
| 101 | CodePointList2 to;
|
---|
| 102 | } CaseUnfold_13_Type;
|
---|
| 103 |
|
---|
| 104 | static inline int
|
---|
| 105 | bits_of(const OnigCodePoint c, const int n)
|
---|
| 106 | {
|
---|
| 107 | return (c >> (2 - n) * 7) & 127;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | static inline int
|
---|
| 111 | bits_at(const OnigCodePoint *c, const int n)
|
---|
| 112 | {
|
---|
| 113 | return bits_of(c[n / 3], n % 3);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | static int
|
---|
| 117 | code1_equal(const OnigCodePoint x, const OnigCodePoint y)
|
---|
| 118 | {
|
---|
| 119 | if (x != y) return 0;
|
---|
| 120 | return 1;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | static int
|
---|
| 124 | code2_equal(const OnigCodePoint *x, const OnigCodePoint *y)
|
---|
| 125 | {
|
---|
| 126 | if (x[0] != y[0]) return 0;
|
---|
| 127 | if (x[1] != y[1]) return 0;
|
---|
| 128 | return 1;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | static int
|
---|
| 132 | code3_equal(const OnigCodePoint *x, const OnigCodePoint *y)
|
---|
| 133 | {
|
---|
| 134 | if (x[0] != y[0]) return 0;
|
---|
| 135 | if (x[1] != y[1]) return 0;
|
---|
| 136 | if (x[2] != y[2]) return 0;
|
---|
| 137 | return 1;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | #include "enc/unicode/casefold.h"
|
---|
| 141 |
|
---|
| 142 | #include "enc/unicode/name2ctype.h"
|
---|
| 143 |
|
---|
| 144 | #define CODE_RANGES_NUM numberof(CodeRanges)
|
---|
| 145 |
|
---|
| 146 | extern int
|
---|
| 147 | onigenc_unicode_is_code_ctype(OnigCodePoint code, unsigned int ctype)
|
---|
| 148 | {
|
---|
| 149 | if (
|
---|
| 150 | #ifdef USE_UNICODE_PROPERTIES
|
---|
| 151 | ctype <= ONIGENC_MAX_STD_CTYPE &&
|
---|
| 152 | #endif
|
---|
| 153 | code < 256) {
|
---|
| 154 | return ONIGENC_IS_UNICODE_ISO_8859_1_CTYPE(code, ctype);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | if (ctype >= CODE_RANGES_NUM) {
|
---|
| 158 | return ONIGERR_TYPE_BUG;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | return onig_is_in_code_range((UChar* )CodeRanges[ctype], code);
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | extern int
|
---|
| 166 | onigenc_unicode_ctype_code_range(int ctype, const OnigCodePoint* ranges[])
|
---|
| 167 | {
|
---|
| 168 | if (ctype >= CODE_RANGES_NUM) {
|
---|
| 169 | return ONIGERR_TYPE_BUG;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | *ranges = CodeRanges[ctype];
|
---|
| 173 |
|
---|
| 174 | return 0;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | extern int
|
---|
| 178 | onigenc_utf16_32_get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
|
---|
| 179 | const OnigCodePoint* ranges[])
|
---|
| 180 | {
|
---|
| 181 | *sb_out = 0x00;
|
---|
| 182 | return onigenc_unicode_ctype_code_range(ctype, ranges);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | #include "st.h"
|
---|
| 186 |
|
---|
| 187 | #define PROPERTY_NAME_MAX_SIZE (MAX_WORD_LENGTH + 1)
|
---|
| 188 |
|
---|
| 189 | extern int
|
---|
| 190 | onigenc_unicode_property_name_to_ctype(OnigEncoding enc, UChar* name, UChar* end)
|
---|
| 191 | {
|
---|
| 192 | int len;
|
---|
| 193 | int ctype;
|
---|
| 194 | UChar buf[PROPERTY_NAME_MAX_SIZE];
|
---|
| 195 | UChar *p;
|
---|
| 196 | OnigCodePoint code;
|
---|
| 197 |
|
---|
| 198 | len = 0;
|
---|
| 199 | for (p = name; p < end; p += enclen(enc, p)) {
|
---|
| 200 | code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
---|
| 201 | if (code == ' ' || code == '-' || code == '_')
|
---|
| 202 | continue;
|
---|
| 203 | if (code >= 0x80)
|
---|
| 204 | return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
---|
| 205 |
|
---|
| 206 | buf[len++] = ONIGENC_ASCII_CODE_TO_LOWER_CASE(code);
|
---|
| 207 | if (len >= PROPERTY_NAME_MAX_SIZE)
|
---|
| 208 | return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | buf[len] = 0;
|
---|
| 212 |
|
---|
| 213 | if ((ctype = uniname2ctype(buf, len)) < 0) {
|
---|
| 214 | return ONIGERR_INVALID_CHAR_PROPERTY_NAME;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | return ctype;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | #define onigenc_unicode_fold_lookup onigenc_unicode_CaseFold_11_lookup
|
---|
| 221 | #define onigenc_unicode_unfold1_lookup onigenc_unicode_CaseUnfold_11_lookup
|
---|
| 222 | #define onigenc_unicode_unfold2_lookup onigenc_unicode_CaseUnfold_12_lookup
|
---|
| 223 | #define onigenc_unicode_unfold3_lookup onigenc_unicode_CaseUnfold_13_lookup
|
---|
| 224 |
|
---|
| 225 | extern int
|
---|
| 226 | onigenc_unicode_mbc_case_fold(OnigEncoding enc,
|
---|
| 227 | OnigCaseFoldType flag ARG_UNUSED, const UChar** pp, const UChar* end,
|
---|
| 228 | UChar* fold)
|
---|
| 229 | {
|
---|
| 230 | const CodePointList3 *to;
|
---|
| 231 | OnigCodePoint code;
|
---|
| 232 | int i, len, rlen;
|
---|
| 233 | const UChar *p = *pp;
|
---|
| 234 |
|
---|
| 235 | code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
---|
| 236 | len = enclen(enc, p);
|
---|
| 237 | *pp += len;
|
---|
| 238 |
|
---|
| 239 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 240 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
---|
| 241 | if (code == 0x0049) {
|
---|
| 242 | return ONIGENC_CODE_TO_MBC(enc, 0x0131, fold);
|
---|
| 243 | }
|
---|
| 244 | else if (code == 0x0130) {
|
---|
| 245 | return ONIGENC_CODE_TO_MBC(enc, 0x0069, fold);
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 | #endif
|
---|
| 249 |
|
---|
| 250 | if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
|
---|
| 251 | if (to->n == 1) {
|
---|
| 252 | return ONIGENC_CODE_TO_MBC(enc, to->code[0], fold);
|
---|
| 253 | }
|
---|
| 254 | #if 0
|
---|
| 255 | /* NO NEEDS TO CHECK */
|
---|
| 256 | else if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0)
|
---|
| 257 | #else
|
---|
| 258 | else
|
---|
| 259 | #endif
|
---|
| 260 | {
|
---|
| 261 | rlen = 0;
|
---|
| 262 | for (i = 0; i < to->n; i++) {
|
---|
| 263 | len = ONIGENC_CODE_TO_MBC(enc, to->code[i], fold);
|
---|
| 264 | fold += len;
|
---|
| 265 | rlen += len;
|
---|
| 266 | }
|
---|
| 267 | return rlen;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | for (i = 0; i < len; i++) {
|
---|
| 272 | *fold++ = *p++;
|
---|
| 273 | }
|
---|
| 274 | return len;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | extern int
|
---|
| 278 | onigenc_unicode_apply_all_case_fold(OnigCaseFoldType flag,
|
---|
| 279 | OnigApplyAllCaseFoldFunc f, void* arg)
|
---|
| 280 | {
|
---|
| 281 | const CaseUnfold_11_Type* p11;
|
---|
| 282 | OnigCodePoint code;
|
---|
| 283 | int i, j, k, r;
|
---|
| 284 |
|
---|
| 285 | for (i = 0; i < numberof(CaseUnfold_11); i++) {
|
---|
| 286 | p11 = &CaseUnfold_11[i];
|
---|
| 287 | for (j = 0; j < p11->to.n; j++) {
|
---|
| 288 | code = p11->from;
|
---|
| 289 | r = (*f)(p11->to.code[j], &code, 1, arg);
|
---|
| 290 | if (r != 0) return r;
|
---|
| 291 |
|
---|
| 292 | code = p11->to.code[j];
|
---|
| 293 | r = (*f)(p11->from, &code, 1, arg);
|
---|
| 294 | if (r != 0) return r;
|
---|
| 295 |
|
---|
| 296 | for (k = 0; k < j; k++) {
|
---|
| 297 | r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]), 1, arg);
|
---|
| 298 | if (r != 0) return r;
|
---|
| 299 |
|
---|
| 300 | r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]), 1, arg);
|
---|
| 301 | if (r != 0) return r;
|
---|
| 302 | }
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 307 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
---|
| 308 | code = 0x0131;
|
---|
| 309 | r = (*f)(0x0049, &code, 1, arg);
|
---|
| 310 | if (r != 0) return r;
|
---|
| 311 | code = 0x0049;
|
---|
| 312 | r = (*f)(0x0131, &code, 1, arg);
|
---|
| 313 | if (r != 0) return r;
|
---|
| 314 |
|
---|
| 315 | code = 0x0130;
|
---|
| 316 | r = (*f)(0x0069, &code, 1, arg);
|
---|
| 317 | if (r != 0) return r;
|
---|
| 318 | code = 0x0069;
|
---|
| 319 | r = (*f)(0x0130, &code, 1, arg);
|
---|
| 320 | if (r != 0) return r;
|
---|
| 321 | }
|
---|
| 322 | else {
|
---|
| 323 | #endif
|
---|
| 324 | for (i = 0; i < numberof(CaseUnfold_11_Locale); i++) {
|
---|
| 325 | p11 = &CaseUnfold_11_Locale[i];
|
---|
| 326 | for (j = 0; j < p11->to.n; j++) {
|
---|
| 327 | code = p11->from;
|
---|
| 328 | r = (*f)(p11->to.code[j], &code, 1, arg);
|
---|
| 329 | if (r != 0) return r;
|
---|
| 330 |
|
---|
| 331 | code = p11->to.code[j];
|
---|
| 332 | r = (*f)(p11->from, &code, 1, arg);
|
---|
| 333 | if (r != 0) return r;
|
---|
| 334 |
|
---|
| 335 | for (k = 0; k < j; k++) {
|
---|
| 336 | r = (*f)(p11->to.code[j], (OnigCodePoint* )(&p11->to.code[k]),
|
---|
| 337 | 1, arg);
|
---|
| 338 | if (r != 0) return r;
|
---|
| 339 |
|
---|
| 340 | r = (*f)(p11->to.code[k], (OnigCodePoint* )(&p11->to.code[j]),
|
---|
| 341 | 1, arg);
|
---|
| 342 | if (r != 0) return r;
|
---|
| 343 | }
|
---|
| 344 | }
|
---|
| 345 | }
|
---|
| 346 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 347 | }
|
---|
| 348 | #endif
|
---|
| 349 |
|
---|
| 350 | if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
---|
| 351 | for (i = 0; i < numberof(CaseUnfold_12); i++) {
|
---|
| 352 | for (j = 0; j < CaseUnfold_12[i].to.n; j++) {
|
---|
| 353 | r = (*f)(CaseUnfold_12[i].to.code[j],
|
---|
| 354 | (OnigCodePoint* )CaseUnfold_12[i].from, 2, arg);
|
---|
| 355 | if (r != 0) return r;
|
---|
| 356 |
|
---|
| 357 | for (k = 0; k < CaseUnfold_12[i].to.n; k++) {
|
---|
| 358 | if (k == j) continue;
|
---|
| 359 |
|
---|
| 360 | r = (*f)(CaseUnfold_12[i].to.code[j],
|
---|
| 361 | (OnigCodePoint* )(&CaseUnfold_12[i].to.code[k]), 1, arg);
|
---|
| 362 | if (r != 0) return r;
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 368 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) == 0) {
|
---|
| 369 | #endif
|
---|
| 370 | for (i = 0; i < numberof(CaseUnfold_12_Locale); i++) {
|
---|
| 371 | for (j = 0; j < CaseUnfold_12_Locale[i].to.n; j++) {
|
---|
| 372 | r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
|
---|
| 373 | (OnigCodePoint* )CaseUnfold_12_Locale[i].from, 2, arg);
|
---|
| 374 | if (r != 0) return r;
|
---|
| 375 |
|
---|
| 376 | for (k = 0; k < CaseUnfold_12_Locale[i].to.n; k++) {
|
---|
| 377 | if (k == j) continue;
|
---|
| 378 |
|
---|
| 379 | r = (*f)(CaseUnfold_12_Locale[i].to.code[j],
|
---|
| 380 | (OnigCodePoint* )(&CaseUnfold_12_Locale[i].to.code[k]),
|
---|
| 381 | 1, arg);
|
---|
| 382 | if (r != 0) return r;
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | }
|
---|
| 386 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 387 | }
|
---|
| 388 | #endif
|
---|
| 389 |
|
---|
| 390 | for (i = 0; i < numberof(CaseUnfold_13); i++) {
|
---|
| 391 | for (j = 0; j < CaseUnfold_13[i].to.n; j++) {
|
---|
| 392 | r = (*f)(CaseUnfold_13[i].to.code[j],
|
---|
| 393 | (OnigCodePoint* )CaseUnfold_13[i].from, 3, arg);
|
---|
| 394 | if (r != 0) return r;
|
---|
| 395 |
|
---|
| 396 | for (k = 0; k < CaseUnfold_13[i].to.n; k++) {
|
---|
| 397 | if (k == j) continue;
|
---|
| 398 |
|
---|
| 399 | r = (*f)(CaseUnfold_13[i].to.code[j],
|
---|
| 400 | (OnigCodePoint* )(&CaseUnfold_13[i].to.code[k]), 1, arg);
|
---|
| 401 | if (r != 0) return r;
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | return 0;
|
---|
| 408 | }
|
---|
| 409 |
|
---|
| 410 | extern int
|
---|
| 411 | onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc,
|
---|
| 412 | OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end,
|
---|
| 413 | OnigCaseFoldCodeItem items[])
|
---|
| 414 | {
|
---|
| 415 | int n, i, j, k, len;
|
---|
| 416 | OnigCodePoint code, codes[3];
|
---|
| 417 | const CodePointList3 *to, *z3;
|
---|
| 418 | const CodePointList2 *z2;
|
---|
| 419 |
|
---|
| 420 | n = 0;
|
---|
| 421 |
|
---|
| 422 | code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
---|
| 423 | len = enclen(enc, p);
|
---|
| 424 |
|
---|
| 425 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
|
---|
| 426 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
|
---|
| 427 | if (code == 0x0049) {
|
---|
| 428 | items[0].byte_len = len;
|
---|
| 429 | items[0].code_len = 1;
|
---|
| 430 | items[0].code[0] = 0x0131;
|
---|
| 431 | return 1;
|
---|
| 432 | }
|
---|
| 433 | else if (code == 0x0130) {
|
---|
| 434 | items[0].byte_len = len;
|
---|
| 435 | items[0].code_len = 1;
|
---|
| 436 | items[0].code[0] = 0x0069;
|
---|
| 437 | return 1;
|
---|
| 438 | }
|
---|
| 439 | else if (code == 0x0131) {
|
---|
| 440 | items[0].byte_len = len;
|
---|
| 441 | items[0].code_len = 1;
|
---|
| 442 | items[0].code[0] = 0x0049;
|
---|
| 443 | return 1;
|
---|
| 444 | }
|
---|
| 445 | else if (code == 0x0069) {
|
---|
| 446 | items[0].byte_len = len;
|
---|
| 447 | items[0].code_len = 1;
|
---|
| 448 | items[0].code[0] = 0x0130;
|
---|
| 449 | return 1;
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 | #endif
|
---|
| 453 |
|
---|
| 454 | if ((to = onigenc_unicode_fold_lookup(code)) != 0) {
|
---|
| 455 | if (to->n == 1) {
|
---|
| 456 | OnigCodePoint orig_code = code;
|
---|
| 457 |
|
---|
| 458 | items[0].byte_len = len;
|
---|
| 459 | items[0].code_len = 1;
|
---|
| 460 | items[0].code[0] = to->code[0];
|
---|
| 461 | n++;
|
---|
| 462 |
|
---|
| 463 | code = to->code[0];
|
---|
| 464 | if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
|
---|
| 465 | for (i = 0; i < to->n; i++) {
|
---|
| 466 | if (to->code[i] != orig_code) {
|
---|
| 467 | items[n].byte_len = len;
|
---|
| 468 | items[n].code_len = 1;
|
---|
| 469 | items[n].code[0] = to->code[i];
|
---|
| 470 | n++;
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | else if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
---|
| 476 | OnigCodePoint cs[3][4];
|
---|
| 477 | int fn, ncs[3];
|
---|
| 478 |
|
---|
| 479 | for (fn = 0; fn < to->n; fn++) {
|
---|
| 480 | cs[fn][0] = to->code[fn];
|
---|
| 481 | if ((z3 = onigenc_unicode_unfold1_lookup(cs[fn][0])) != 0) {
|
---|
| 482 | for (i = 0; i < z3->n; i++) {
|
---|
| 483 | cs[fn][i+1] = z3->code[i];
|
---|
| 484 | }
|
---|
| 485 | ncs[fn] = z3->n + 1;
|
---|
| 486 | }
|
---|
| 487 | else
|
---|
| 488 | ncs[fn] = 1;
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | if (fn == 2) {
|
---|
| 492 | for (i = 0; i < ncs[0]; i++) {
|
---|
| 493 | for (j = 0; j < ncs[1]; j++) {
|
---|
| 494 | items[n].byte_len = len;
|
---|
| 495 | items[n].code_len = 2;
|
---|
| 496 | items[n].code[0] = cs[0][i];
|
---|
| 497 | items[n].code[1] = cs[1][j];
|
---|
| 498 | n++;
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | if ((z2 = onigenc_unicode_unfold2_lookup(to->code)) != 0) {
|
---|
| 503 | for (i = 0; i < z2->n; i++) {
|
---|
| 504 | if (z2->code[i] == code) continue;
|
---|
| 505 |
|
---|
| 506 | items[n].byte_len = len;
|
---|
| 507 | items[n].code_len = 1;
|
---|
| 508 | items[n].code[0] = z2->code[i];
|
---|
| 509 | n++;
|
---|
| 510 | }
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
| 513 | else {
|
---|
| 514 | for (i = 0; i < ncs[0]; i++) {
|
---|
| 515 | for (j = 0; j < ncs[1]; j++) {
|
---|
| 516 | for (k = 0; k < ncs[2]; k++) {
|
---|
| 517 | items[n].byte_len = len;
|
---|
| 518 | items[n].code_len = 3;
|
---|
| 519 | items[n].code[0] = cs[0][i];
|
---|
| 520 | items[n].code[1] = cs[1][j];
|
---|
| 521 | items[n].code[2] = cs[2][k];
|
---|
| 522 | n++;
|
---|
| 523 | }
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 |
|
---|
| 527 | if ((z2 = onigenc_unicode_unfold3_lookup(to->code)) != 0) {
|
---|
| 528 | for (i = 0; i < z2->n; i++) {
|
---|
| 529 | if (z2->code[i] == code) continue;
|
---|
| 530 |
|
---|
| 531 | items[n].byte_len = len;
|
---|
| 532 | items[n].code_len = 1;
|
---|
| 533 | items[n].code[0] = z2->code[i];
|
---|
| 534 | n++;
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
| 538 |
|
---|
| 539 | /* multi char folded code is not head of another folded multi char */
|
---|
| 540 | flag = 0; /* DISABLE_CASE_FOLD_MULTI_CHAR(flag); */
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 | else {
|
---|
| 544 | if ((to = onigenc_unicode_unfold1_lookup(code)) != 0) {
|
---|
| 545 | for (i = 0; i < to->n; i++) {
|
---|
| 546 | items[n].byte_len = len;
|
---|
| 547 | items[n].code_len = 1;
|
---|
| 548 | items[n].code[0] = to->code[i];
|
---|
| 549 | n++;
|
---|
| 550 | }
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 |
|
---|
| 554 |
|
---|
| 555 | if ((flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
|
---|
| 556 | p += len;
|
---|
| 557 | if (p < end) {
|
---|
| 558 | int clen;
|
---|
| 559 |
|
---|
| 560 | codes[0] = code;
|
---|
| 561 | code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
---|
| 562 | if ((to = onigenc_unicode_fold_lookup(code)) != 0
|
---|
| 563 | && to->n == 1) {
|
---|
| 564 | codes[1] = to->code[0];
|
---|
| 565 | }
|
---|
| 566 | else
|
---|
| 567 | codes[1] = code;
|
---|
| 568 |
|
---|
| 569 | clen = enclen(enc, p);
|
---|
| 570 | len += clen;
|
---|
| 571 | if ((z2 = onigenc_unicode_unfold2_lookup(codes)) != 0) {
|
---|
| 572 | for (i = 0; i < z2->n; i++) {
|
---|
| 573 | items[n].byte_len = len;
|
---|
| 574 | items[n].code_len = 1;
|
---|
| 575 | items[n].code[0] = z2->code[i];
|
---|
| 576 | n++;
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | p += clen;
|
---|
| 581 | if (p < end) {
|
---|
| 582 | code = ONIGENC_MBC_TO_CODE(enc, p, end);
|
---|
| 583 | if ((to = onigenc_unicode_fold_lookup(code)) != 0
|
---|
| 584 | && to->n == 1) {
|
---|
| 585 | codes[2] = to->code[0];
|
---|
| 586 | }
|
---|
| 587 | else
|
---|
| 588 | codes[2] = code;
|
---|
| 589 |
|
---|
| 590 | clen = enclen(enc, p);
|
---|
| 591 | len += clen;
|
---|
| 592 | if ((z2 = onigenc_unicode_unfold3_lookup(codes)) != 0) {
|
---|
| 593 | for (i = 0; i < z2->n; i++) {
|
---|
| 594 | items[n].byte_len = len;
|
---|
| 595 | items[n].code_len = 1;
|
---|
| 596 | items[n].code[0] = z2->code[i];
|
---|
| 597 | n++;
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 | }
|
---|
| 601 | }
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | return n;
|
---|
| 605 | }
|
---|