From: K.Kosako Date: Mon, 8 Oct 2018 07:58:20 +0000 (+0900) Subject: use ENC_FLAG_SKIP_OFFSET_XXX values X-Git-Tag: v6.9.1~18^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7606c2aacf72d4426d83bb5544732f9372fc6ab;p=onig use ENC_FLAG_SKIP_OFFSET_XXX values --- diff --git a/src/regcomp.c b/src/regcomp.c index e051fb2..78a340f 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -4632,21 +4632,14 @@ set_sunday_quick_search_skip_table(regex_t* reg, int case_expand, UChar buf[ONIGENC_MBC_CASE_FOLD_MAXLEN]; enc = reg->enc; - - offset = 1; - if (ONIGENC_MBC_MINLEN(enc) > 1) { + offset = ENC_GET_SKIP_OFFSET(enc); + if (offset == ENC_SKIP_OFFSET_1_OR_0) { UChar* p = s; while (1) { len = enclen(enc, p); if (p + len >= end) { - UChar* q = p + (ONIGENC_MBC_MINLEN(enc) - 1); - while (q > p) { - if (*q != '\0') { - offset = (int )(q - p + 1); - break; - } - q--; - } + if (len == 1) offset = 1; + else offset = 0; break; } p += len; @@ -4664,12 +4657,16 @@ set_sunday_quick_search_skip_table(regex_t* reg, int case_expand, } for (p = s; p < end; ) { + int z; + clen = enclen(enc, p); if (p + clen > end) clen = (int )(end - p); len = (int )(end - p); for (j = 0; j < clen; j++) { - skip[p[j]] = len - j + (offset - 1); + z = len - j + (offset - 1); + if (z <= 0) break; + skip[p[j]] = z; } if (case_expand != 0) { @@ -4678,7 +4675,8 @@ set_sunday_quick_search_skip_table(regex_t* reg, int case_expand, for (k = 0; k < n; k++) { ONIGENC_CODE_TO_MBC(enc, items[k].code[0], buf); for (j = 0; j < clen; j++) { - int z = len - j + (offset - 1); + z = len - j + (offset - 1); + if (z <= 0) break; if (skip[buf[j]] > z) skip[buf[j]] = z; } diff --git a/src/regenc.h b/src/regenc.h index 64adb3e..8a3397d 100644 --- a/src/regenc.h +++ b/src/regenc.h @@ -121,6 +121,8 @@ struct PropertyNameCtype { #define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII +#define ENC_SKIP_OFFSET_1_OR_0 7 + #define ENC_FLAG_ASCII_COMPATIBLE (1<<0) #define ENC_FLAG_UNICODE (1<<1) #define ENC_FLAG_SKIP_OFFSET_MASK (7<<2) @@ -129,9 +131,10 @@ struct PropertyNameCtype { #define ENC_FLAG_SKIP_OFFSET_2 (2<<2) #define ENC_FLAG_SKIP_OFFSET_3 (3<<2) #define ENC_FLAG_SKIP_OFFSET_4 (4<<2) -#define ENC_FLAG_SKIP_OFFSET_1_OR_0 (7<<2) +#define ENC_FLAG_SKIP_OFFSET_1_OR_0 (ENC_SKIP_OFFSET_1_OR_0<<2) -#define ENC_GET_SKIP_OFFSET(flag) ((flag)>>2) +#define ENC_GET_SKIP_OFFSET(enc) \ + (((enc)->flag & ENC_FLAG_SKIP_OFFSET_MASK)>>2) /* for encoding system implementation (internal) */