1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* regexec.c (string_cmp_ic): add text_end argument.

(slow_search): call enclen with real string end.
  (map_search): add text_end argument.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-09-18 16:16:45 +00:00
parent f0c8c9d832
commit 478b14ea4f
3 changed files with 25 additions and 16 deletions

View file

@ -1,3 +1,9 @@
Fri Sep 19 01:07:36 2008 Tanaka Akira <akr@fsij.org>
* regexec.c (string_cmp_ic): add text_end argument.
(slow_search): call enclen with real string end.
(map_search): add text_end argument.
Thu Sep 18 22:54:39 2008 Yusuke Endoh <mame@tsg.ne.jp> Thu Sep 18 22:54:39 2008 Yusuke Endoh <mame@tsg.ne.jp>
* ext/openssl/ossl_pkey_ec.c (ossl_ec_key_to_string): comment out * ext/openssl/ossl_pkey_ec.c (ossl_ec_key_to_string): comment out

View file

@ -977,25 +977,24 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,
}\ }\
} while(0) } while(0)
#define STRING_CMP_IC(case_fold_flag,s1,ps2,len) do {\ #define STRING_CMP_IC(case_fold_flag,s1,ps2,len,text_end) do {\
if (string_cmp_ic(encode, case_fold_flag, s1, ps2, len) == 0) \ if (string_cmp_ic(encode, case_fold_flag, s1, ps2, len, text_end) == 0) \
goto fail; \ goto fail; \
} while(0) } while(0)
static int string_cmp_ic(OnigEncoding enc, int case_fold_flag, static int string_cmp_ic(OnigEncoding enc, int case_fold_flag,
UChar* s1, UChar** ps2, int mblen) UChar* s1, UChar** ps2, int mblen, const UChar* text_end)
{ {
UChar buf1[ONIGENC_MBC_CASE_FOLD_MAXLEN]; UChar buf1[ONIGENC_MBC_CASE_FOLD_MAXLEN];
UChar buf2[ONIGENC_MBC_CASE_FOLD_MAXLEN]; UChar buf2[ONIGENC_MBC_CASE_FOLD_MAXLEN];
UChar *p1, *p2, *end1, *s2, *end2; UChar *p1, *p2, *end1, *s2;
int len1, len2; int len1, len2;
s2 = *ps2; s2 = *ps2;
end1 = s1 + mblen; end1 = s1 + mblen;
end2 = s2 + mblen;
while (s1 < end1) { while (s1 < end1) {
len1 = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &s1, end1, buf1); len1 = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &s1, text_end, buf1);
len2 = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &s2, end2, buf2); len2 = ONIGENC_MBC_CASE_FOLD(enc, case_fold_flag, &s2, text_end, buf2);
if (len1 != len2) return 0; if (len1 != len2) return 0;
p1 = buf1; p1 = buf1;
p2 = buf2; p2 = buf2;
@ -1019,8 +1018,8 @@ static int string_cmp_ic(OnigEncoding enc, int case_fold_flag,
}\ }\
} while(0) } while(0)
#define STRING_CMP_VALUE_IC(case_fold_flag,s1,ps2,len,is_fail) do {\ #define STRING_CMP_VALUE_IC(case_fold_flag,s1,ps2,len,text_end,is_fail) do {\
if (string_cmp_ic(encode, case_fold_flag, s1, ps2, len) == 0) \ if (string_cmp_ic(encode, case_fold_flag, s1, ps2, len, text_end) == 0) \
is_fail = 1; \ is_fail = 1; \
else \ else \
is_fail = 0; \ is_fail = 0; \
@ -1126,7 +1125,7 @@ static int backref_match_at_nested_level(regex_t* reg
if (ignore_case != 0) { if (ignore_case != 0) {
if (string_cmp_ic(reg->enc, case_fold_flag, if (string_cmp_ic(reg->enc, case_fold_flag,
pstart, &ss, (int )(pend - pstart)) == 0) pstart, &ss, (int )(pend - pstart), send) == 0)
return 0; /* or goto next_mem; */ return 0; /* or goto next_mem; */
} }
else { else {
@ -2199,7 +2198,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
n = pend - pstart; n = pend - pstart;
DATA_ENSURE(n); DATA_ENSURE(n);
sprev = s; sprev = s;
STRING_CMP_IC(case_fold_flag, pstart, &s, n); STRING_CMP_IC(case_fold_flag, pstart, &s, n, end);
while (sprev + (len = enclen(encode, sprev, end)) < s) while (sprev + (len = enclen(encode, sprev, end)) < s)
sprev += len; sprev += len;
@ -2271,7 +2270,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
DATA_ENSURE(n); DATA_ENSURE(n);
sprev = s; sprev = s;
swork = s; swork = s;
STRING_CMP_VALUE_IC(case_fold_flag, pstart, &swork, n, is_fail); STRING_CMP_VALUE_IC(case_fold_flag, pstart, &swork, n, end, is_fail);
if (is_fail) continue; if (is_fail) continue;
s = swork; s = swork;
while (sprev + (len = enclen(encode, sprev, end)) < s) while (sprev + (len = enclen(encode, sprev, end)) < s)
@ -2780,7 +2779,7 @@ slow_search(OnigEncoding enc, UChar* target, UChar* target_end,
if (target_end == t || memcmp(t, p, target_end - t) == 0) if (target_end == t || memcmp(t, p, target_end - t) == 0)
return s; return s;
} }
s += enclen(enc, s, end); s += enclen(enc, s, text_end);
} }
return (UChar* )NULL; return (UChar* )NULL;
@ -3038,14 +3037,14 @@ bm_search_backward(regex_t* reg, const UChar* target, const UChar* target_end,
static UChar* static UChar*
map_search(OnigEncoding enc, UChar map[], map_search(OnigEncoding enc, UChar map[],
const UChar* text, const UChar* text_range) const UChar* text, const UChar* text_range, const UChar* text_end)
{ {
const UChar *s = text; const UChar *s = text;
while (s < text_range) { while (s < text_range) {
if (map[*s]) return (UChar* )s; if (map[*s]) return (UChar* )s;
s += enclen(enc, s, text_range); s += enclen(enc, s, text_end);
} }
return (UChar* )NULL; return (UChar* )NULL;
} }
@ -3171,7 +3170,7 @@ forward_search_range(regex_t* reg, const UChar* str, const UChar* end, UChar* s,
break; break;
case ONIG_OPTIMIZE_MAP: case ONIG_OPTIMIZE_MAP:
p = map_search(reg->enc, reg->map, p, range); p = map_search(reg->enc, reg->map, p, range, end);
break; break;
} }

View file

@ -17,4 +17,8 @@ class TestEUC_JP < Test::Unit::TestCase
assert_no_match(/あ{0}\p{Katakana}{4}/, "戳机戳机") assert_no_match(/あ{0}\p{Katakana}{4}/, "戳机戳机")
assert_raise(RegexpError) { Regexp.new('あ{0}\p{foobarbaz}') } assert_raise(RegexpError) { Regexp.new('あ{0}\p{foobarbaz}') }
end end
def test_charboundary
assert_nil(/\xA2\xA2/ =~ "\xA1\xA2\xA2\xA3")
end
end end