summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-13 19:23:52 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-13 19:23:52 (GMT)
commit19416601a0af3b7c99a570ae6993cb29e4360e64 (patch)
treea7406d81b554109333ea2240825897a87ebdfe4b
parent10ff0f292e9b7cd673915fcc32f5d236c95c8d7d (diff)
* include/ruby/oniguruma.h (OnigEncodingTypeST): add end argument for
left_adjust_char_head. (ONIGENC_LEFT_ADJUST_CHAR_HEAD): add end argument. (onigenc_get_left_adjust_char_head): ditto. * include/ruby/encoding.h (rb_enc_left_char_head): add end argument. * regenc.h (onigenc_single_byte_left_adjust_char_head): ditto. * regenc.c (onigenc_get_right_adjust_char_head): follow the interface change. (onigenc_get_right_adjust_char_head_with_prev): ditto. (onigenc_get_prev_char_head): ditto. (onigenc_step_back): ditto. (onigenc_get_left_adjust_char_head): ditto. (onigenc_single_byte_code_to_mbc): ditto. * re.c: ditto. * string.c: ditto. * io.c: ditto. * regexec.c: ditto. * enc/euc_jp.c: ditto. * enc/cp949.c: ditto. * enc/shift_jis.c: ditto. * enc/gbk.c: ditto. * enc/big5.c: ditto. * enc/euc_tw.c: ditto. * enc/euc_kr.c: ditto. * enc/emacs_mule.c: ditto. * enc/gb18030.c: ditto. * enc/utf_8.c: ditto. * enc/utf_16le.c: ditto. * enc/utf_16be.c: ditto. * enc/utf_32le.c: ditto. * enc/utf_32be.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog55
-rw-r--r--enc/big5.c4
-rw-r--r--enc/cp949.c4
-rw-r--r--enc/emacs_mule.c2
-rw-r--r--enc/euc_jp.c4
-rw-r--r--enc/euc_kr.c4
-rw-r--r--enc/euc_tw.c4
-rw-r--r--enc/gb18030.c2
-rw-r--r--enc/gbk.c4
-rw-r--r--enc/shift_jis.c4
-rw-r--r--enc/utf_16be.c2
-rw-r--r--enc/utf_16le.c2
-rw-r--r--enc/utf_32be.c2
-rw-r--r--enc/utf_32le.c2
-rw-r--r--enc/utf_8.c2
-rw-r--r--include/ruby/encoding.h2
-rw-r--r--include/ruby/oniguruma.h8
-rw-r--r--io.c9
-rw-r--r--re.c2
-rw-r--r--regenc.c13
-rw-r--r--regenc.h2
-rw-r--r--regexec.c14
-rw-r--r--string.c15
23 files changed, 110 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index e4a4b06..c99d660 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,58 @@
+Sun Sep 14 04:15:16 2008 Tanaka Akira <akr@fsij.org>
+
+ * include/ruby/oniguruma.h (OnigEncodingTypeST): add end argument for
+ left_adjust_char_head.
+ (ONIGENC_LEFT_ADJUST_CHAR_HEAD): add end argument.
+ (onigenc_get_left_adjust_char_head): ditto.
+
+ * include/ruby/encoding.h (rb_enc_left_char_head): add end argument.
+
+ * regenc.h (onigenc_single_byte_left_adjust_char_head): ditto.
+
+ * regenc.c (onigenc_get_right_adjust_char_head): follow the interface
+ change.
+ (onigenc_get_right_adjust_char_head_with_prev): ditto.
+ (onigenc_get_prev_char_head): ditto.
+ (onigenc_step_back): ditto.
+ (onigenc_get_left_adjust_char_head): ditto.
+ (onigenc_single_byte_code_to_mbc): ditto.
+
+ * re.c: ditto.
+
+ * string.c: ditto.
+
+ * io.c: ditto.
+
+ * regexec.c: ditto.
+
+ * enc/euc_jp.c: ditto.
+
+ * enc/cp949.c: ditto.
+
+ * enc/shift_jis.c: ditto.
+
+ * enc/gbk.c: ditto.
+
+ * enc/big5.c: ditto.
+
+ * enc/euc_tw.c: ditto.
+
+ * enc/euc_kr.c: ditto.
+
+ * enc/emacs_mule.c: ditto.
+
+ * enc/gb18030.c: ditto.
+
+ * enc/utf_8.c: ditto.
+
+ * enc/utf_16le.c: ditto.
+
+ * enc/utf_16be.c: ditto.
+
+ * enc/utf_32le.c: ditto.
+
+ * enc/utf_32be.c: ditto.
+
Sun Sep 14 03:43:27 2008 Tanaka Akira <akr@fsij.org>
* include/ruby/oniguruma.h (ONIGENC_STEP_BACK): add end argument.
diff --git a/enc/big5.c b/enc/big5.c
index 70a316e..9993f47 100644
--- a/enc/big5.c
+++ b/enc/big5.c
@@ -165,7 +165,7 @@ static const char BIG5_CAN_BE_TRAIL_TABLE[256] = {
#define BIG5_ISMB_TRAIL(byte) BIG5_CAN_BE_TRAIL_TABLE[(byte)]
static UChar*
-big5_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+big5_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
int len;
@@ -181,7 +181,7 @@ big5_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
}
}
}
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/cp949.c b/enc/cp949.c
index 0046460..009443a 100644
--- a/enc/cp949.c
+++ b/enc/cp949.c
@@ -165,7 +165,7 @@ cp949_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
}
static UChar*
-cp949_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+cp949_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
int len;
@@ -181,7 +181,7 @@ cp949_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc
}
}
}
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/emacs_mule.c b/enc/emacs_mule.c
index e97bb6a..be7f842 100644
--- a/enc/emacs_mule.c
+++ b/enc/emacs_mule.c
@@ -293,7 +293,7 @@ mbc_case_fold(OnigCaseFoldType flag,
}
static UChar*
-left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
diff --git a/enc/euc_jp.c b/enc/euc_jp.c
index fb8bf41..21f30ad 100644
--- a/enc/euc_jp.c
+++ b/enc/euc_jp.c
@@ -222,7 +222,7 @@ mbc_case_fold(OnigCaseFoldType flag,
}
static UChar*
-left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
/* In this encoding
mb-trail bytes doesn't mix with single bytes.
@@ -234,7 +234,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
p = s;
while (!eucjp_islead(*p) && p > start) p--;
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/euc_kr.c b/enc/euc_kr.c
index 1b5ec89..f20a57e 100644
--- a/enc/euc_kr.c
+++ b/enc/euc_kr.c
@@ -145,7 +145,7 @@ euckr_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
#define euckr_islead(c) ((c) < 0xa1 || (c) == 0xff)
static UChar*
-euckr_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+euckr_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
/* Assumed in this encoding,
mb-trail bytes don't mix with single bytes.
@@ -157,7 +157,7 @@ euckr_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc
p = s;
while (!euckr_islead(*p) && p > start) p--;
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/euc_tw.c b/enc/euc_tw.c
index ca38983..d025a0d 100644
--- a/enc/euc_tw.c
+++ b/enc/euc_tw.c
@@ -187,7 +187,7 @@ euctw_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
#define euctw_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
static UChar*
-euctw_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+euctw_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
/* Assumed in this encoding,
mb-trail bytes don't mix with single bytes.
@@ -199,7 +199,7 @@ euctw_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc
p = s;
while (!euctw_islead(*p) && p > start) p--;
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/gb18030.c b/enc/gb18030.c
index 2b707d4..16c8c1c 100644
--- a/enc/gb18030.c
+++ b/enc/gb18030.c
@@ -245,7 +245,7 @@ enum state {
};
static UChar*
-gb18030_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+gb18030_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
enum state state = S_START;
diff --git a/enc/gbk.c b/enc/gbk.c
index 8b45ed4..3efb1bf 100644
--- a/enc/gbk.c
+++ b/enc/gbk.c
@@ -165,7 +165,7 @@ gbk_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
}
static UChar*
-gbk_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+gbk_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
int len;
@@ -181,7 +181,7 @@ gbk_left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
}
}
}
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/shift_jis.c b/enc/shift_jis.c
index f74afff..b4d8592 100644
--- a/enc/shift_jis.c
+++ b/enc/shift_jis.c
@@ -229,7 +229,7 @@ is_code_ctype(OnigCodePoint code, unsigned int ctype)
#endif
static UChar*
-left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
+left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
{
const UChar *p;
int len;
@@ -245,7 +245,7 @@ left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc)
}
}
}
- len = enclen(enc, p, s);
+ len = enclen(enc, p, end);
if (p + len > s) return (UChar* )p;
p += len;
return (UChar* )(p + ((s - p) & ~1));
diff --git a/enc/utf_16be.c b/enc/utf_16be.c
index ccae939..8d7c8e9 100644
--- a/enc/utf_16be.c
+++ b/enc/utf_16be.c
@@ -212,7 +212,7 @@ utf16be_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* e
#endif
static UChar*
-utf16be_left_adjust_char_head(const UChar* start, const UChar* s,
+utf16be_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
OnigEncoding enc ARG_UNUSED)
{
if (s <= start) return (UChar* )s;
diff --git a/enc/utf_16le.c b/enc/utf_16le.c
index c3712f4..c8a1e7a 100644
--- a/enc/utf_16le.c
+++ b/enc/utf_16le.c
@@ -204,7 +204,7 @@ utf16le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp,
#endif
static UChar*
-utf16le_left_adjust_char_head(const UChar* start, const UChar* s,
+utf16le_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
OnigEncoding enc ARG_UNUSED)
{
if (s <= start) return (UChar* )s;
diff --git a/enc/utf_32be.c b/enc/utf_32be.c
index ed6c9b7..61e7d0f 100644
--- a/enc/utf_32be.c
+++ b/enc/utf_32be.c
@@ -152,7 +152,7 @@ utf32be_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* e
#endif
static UChar*
-utf32be_left_adjust_char_head(const UChar* start, const UChar* s,
+utf32be_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
OnigEncoding enc ARG_UNUSED)
{
int rem;
diff --git a/enc/utf_32le.c b/enc/utf_32le.c
index 53e3522..3a0a41b 100644
--- a/enc/utf_32le.c
+++ b/enc/utf_32le.c
@@ -152,7 +152,7 @@ utf32le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* e
#endif
static UChar*
-utf32le_left_adjust_char_head(const UChar* start, const UChar* s,
+utf32le_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
OnigEncoding enc ARG_UNUSED)
{
int rem;
diff --git a/enc/utf_8.c b/enc/utf_8.c
index b8ee92f..3b9387c 100644
--- a/enc/utf_8.c
+++ b/enc/utf_8.c
@@ -405,7 +405,7 @@ get_ctype_code_range(OnigCtype ctype, OnigCodePoint *sb_out,
static UChar*
-left_adjust_char_head(const UChar* start, const UChar* s, OnigEncoding enc ARG_UNUSED)
+left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc ARG_UNUSED)
{
const UChar *p;
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h
index 059f4b0..f2f7ba1 100644
--- a/include/ruby/encoding.h
+++ b/include/ruby/encoding.h
@@ -132,7 +132,7 @@ int rb_enc_codelen(int code, rb_encoding *enc);
/* start, ptr, end, encoding -> prev_char */
#define rb_enc_prev_char(s,p,e,enc) (char *)onigenc_get_prev_char_head(enc,(UChar*)(s),(UChar*)(p),(UChar*)(e))
/* start, ptr, end, encoding -> next_char */
-#define rb_enc_left_char_head(s,p,enc) (char *)onigenc_get_left_adjust_char_head(enc,(UChar*)(s),(UChar*)(p))
+#define rb_enc_left_char_head(s,p,e,enc) (char *)onigenc_get_left_adjust_char_head(enc,(UChar*)(s),(UChar*)(p),(UChar*)(e))
#define rb_enc_right_char_head(s,p,e,enc) (char *)onigenc_get_right_adjust_char_head(enc,(UChar*)(s),(UChar*)(p),(UChar*)(e))
/* ptr, ptr, encoding -> newline_or_not */
diff --git a/include/ruby/oniguruma.h b/include/ruby/oniguruma.h
index 63eba4f..bc6905e 100644
--- a/include/ruby/oniguruma.h
+++ b/include/ruby/oniguruma.h
@@ -164,7 +164,7 @@ typedef struct OnigEncodingTypeST {
int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype, struct OnigEncodingTypeST* enc);
int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], struct OnigEncodingTypeST* enc);
- OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p, struct OnigEncodingTypeST* enc);
+ OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
int ruby_encoding_index;
} OnigEncodingType;
@@ -219,8 +219,8 @@ ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf,enc)
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
(enc)->is_allowed_reverse_match(s,end,enc)
-#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \
- (enc)->left_adjust_char_head(start, s, enc)
+#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s,end) \
+ (enc)->left_adjust_char_head(start, s, end, enc)
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
(enc)->apply_all_case_fold(case_fold_flag,f,arg,enc)
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
@@ -307,7 +307,7 @@ OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, co
ONIG_EXTERN
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
ONIG_EXTERN
-OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s));
+OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
ONIG_EXTERN
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
ONIG_EXTERN
diff --git a/io.c b/io.c
index 2ed7647..66b2afb 100644
--- a/io.c
+++ b/io.c
@@ -2177,13 +2177,14 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
else
enc = io_input_encoding(fptr);
while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
- const char *s, *p, *pp;
+ const char *s, *p, *pp, *e;
if (c == newline) {
if (RSTRING_LEN(str) < rslen) continue;
s = RSTRING_PTR(str);
- p = s + RSTRING_LEN(str) - rslen;
- pp = rb_enc_left_char_head(s, p, enc);
+ e = s + RSTRING_LEN(str);
+ p = e - rslen;
+ pp = rb_enc_left_char_head(s, p, e, enc);
if (pp != p) continue;
if (!rspara) rscheck(rsptr, rslen, rs);
if (memcmp(p, rsptr, rslen) == 0) break;
@@ -2191,7 +2192,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
if (limit == 0) {
s = RSTRING_PTR(str);
p = s + RSTRING_LEN(str);
- pp = rb_enc_left_char_head(s, p-1, enc);
+ pp = rb_enc_left_char_head(s, p-1, p, enc);
if (extra_limit &&
MBCLEN_NEEDMORE_P(rb_enc_precise_mbclen(pp, p, enc))) {
/* relax the limit while incomplete character.
diff --git a/re.c b/re.c
index 82463fe..c0280f5 100644
--- a/re.c
+++ b/re.c
@@ -1267,7 +1267,7 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, int reverse)
p = onigenc_get_right_adjust_char_head(enc, string, string + pos, string + RSTRING_LEN(str));
}
else {
- p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, string, string + pos);
+ p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, string, string + pos, string + RSTRING_LEN(str));
}
return p - string;
}
diff --git a/regenc.c b/regenc.c
index a67774e..634afd8 100644
--- a/regenc.c
+++ b/regenc.c
@@ -64,7 +64,7 @@ onigenc_mbclen_approximate(const OnigUChar* p,const OnigUChar* e, struct OnigEnc
extern UChar*
onigenc_get_right_adjust_char_head(OnigEncoding enc, const UChar* start, const UChar* s, const UChar* end)
{
- UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
+ UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s, end);
if (p < s) {
p += enclen(enc, p, end);
}
@@ -75,7 +75,7 @@ extern UChar*
onigenc_get_right_adjust_char_head_with_prev(OnigEncoding enc,
const UChar* start, const UChar* s, const UChar* end, const UChar** prev)
{
- UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
+ UChar* p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s, end);
if (p < s) {
if (prev) *prev = (const UChar* )p;
@@ -93,7 +93,7 @@ onigenc_get_prev_char_head(OnigEncoding enc, const UChar* start, const UChar* s,
if (s <= start)
return (UChar* )NULL;
- return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1);
+ return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1, end);
}
extern UChar*
@@ -103,7 +103,7 @@ onigenc_step_back(OnigEncoding enc, const UChar* start, const UChar* s, const UC
if (s <= start)
return (UChar* )NULL;
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1);
+ s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s - 1, end);
}
return (UChar* )s;
}
@@ -369,9 +369,9 @@ onigenc_set_default_caseconv_table(const UChar* table ARG_UNUSED)
}
extern UChar*
-onigenc_get_left_adjust_char_head(OnigEncoding enc, const UChar* start, const UChar* s)
+onigenc_get_left_adjust_char_head(OnigEncoding enc, const UChar* start, const UChar* s, const UChar* end)
{
- return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s);
+ return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, start, s, end);
}
const OnigPairCaseFoldCodes OnigAsciiLowerMap[] = {
@@ -637,6 +637,7 @@ onigenc_single_byte_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc
extern UChar*
onigenc_single_byte_left_adjust_char_head(const UChar* start ARG_UNUSED, const UChar* s,
+ const UChar* end,
OnigEncoding enc ARG_UNUSED)
{
return (UChar* )s;
diff --git a/regenc.h b/regenc.h
index 317175f..3844e41 100644
--- a/regenc.h
+++ b/regenc.h
@@ -125,7 +125,7 @@ ONIG_EXTERN int onigenc_single_byte_mbc_enc_len P_((const UChar* p, const UChar*
ONIG_EXTERN OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end, OnigEncoding enc));
ONIG_EXTERN int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code, OnigEncoding enc));
ONIG_EXTERN int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf, OnigEncoding enc));
-ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s, OnigEncoding enc));
+ONIG_EXTERN UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s, const OnigUChar* end, OnigEncoding enc));
ONIG_EXTERN int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
ONIG_EXTERN int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end, OnigEncoding enc));
ONIG_EXTERN int onigenc_ascii_is_code_ctype P_((OnigCodePoint code, unsigned int ctype, OnigEncoding enc));
diff --git a/regexec.c b/regexec.c
index 8941403..c936a60 100644
--- a/regexec.c
+++ b/regexec.c
@@ -2843,7 +2843,7 @@ slow_search_backward(OnigEncoding enc, UChar* target, UChar* target_end,
if (s > text_start)
s = (UChar* )text_start;
else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s);
+ s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s, text_end);
while (s >= text) {
if (*s == *target) {
@@ -2876,7 +2876,7 @@ slow_search_backward_ic(OnigEncoding enc, int case_fold_flag,
if (s > text_start)
s = (UChar* )text_start;
else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s);
+ s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc, adjust_text, s, text_end);
while (s >= text) {
if (str_lower_case_match(enc, case_fold_flag,
@@ -3018,7 +3018,7 @@ bm_search_backward(regex_t* reg, const UChar* target, const UChar* target_end,
if (text_start < s)
s = text_start;
else
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s);
+ s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s, text_end);
while (s >= text) {
p = s;
@@ -3030,7 +3030,7 @@ bm_search_backward(regex_t* reg, const UChar* target, const UChar* target_end,
return (UChar* )s;
s -= reg->int_map_backward[*s];
- s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s);
+ s = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, adjust_text, s, text_end);
}
return (UChar* )NULL;
@@ -3523,7 +3523,7 @@ onig_search(regex_t* reg, const UChar* str, const UChar* end,
}
if ((OnigDistance )(max_semi_end - start) < reg->anchor_dmin) {
start = max_semi_end - reg->anchor_dmin;
- start = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, start);
+ start = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, start, end);
}
if (range > start) goto mismatch_no_msa;
}
@@ -3670,7 +3670,7 @@ onig_search(regex_t* reg, const UChar* str, const UChar* end,
UChar *low, *high, *adjrange, *sch_start;
if (range < end)
- adjrange = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, range);
+ adjrange = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, str, range, end);
else
adjrange = (UChar* )end;
@@ -3706,7 +3706,7 @@ onig_search(regex_t* reg, const UChar* str, const UChar* end,
if (sch_start > end) sch_start = (UChar* )end;
else
sch_start = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc,
- start, sch_start);
+ start, sch_start, end);
}
}
if (backward_search_range(reg, str, end, sch_start, range, adjrange,
diff --git a/string.c b/string.c
index d3af5a4..dd61d52 100644
--- a/string.c
+++ b/string.c
@@ -5179,7 +5179,7 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str)
p = memchr(p, '\n', pend - p);
if (!p) break;
- p0 = rb_enc_left_char_head(s, p, enc);
+ p0 = rb_enc_left_char_head(s, p, pend, enc);
if (!rb_enc_is_newline(p0, pend, enc)) {
p++;
continue;
@@ -5424,13 +5424,13 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
rb_str_modify(str);
enc = rb_enc_get(str);
if (rb_enc_mbminlen(enc) > 1) {
- pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), enc);
+ pp = rb_enc_left_char_head(p, e-rb_enc_mbminlen(enc), e, enc);
if (rb_enc_is_newline(pp, e, enc)) {
e = pp;
}
pp = e - rb_enc_mbminlen(enc);
if (pp >= p) {
- pp = rb_enc_left_char_head(p, pp, enc);
+ pp = rb_enc_left_char_head(p, pp, e, enc);
if (rb_enc_ascget(pp, e, 0, enc) == '\r') {
e = pp;
}
@@ -5493,7 +5493,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
if (p[len-1] == newline &&
(rslen <= 1 ||
memcmp(RSTRING_PTR(rs), pp, rslen) == 0)) {
- if (rb_enc_left_char_head(p, pp, enc) != pp)
+ if (rb_enc_left_char_head(p, pp, e, enc) != pp)
return Qnil;
rb_str_modify(str);
STR_SET_LEN(str, RSTRING_LEN(str) - rslen);
@@ -6284,7 +6284,7 @@ static VALUE
rb_str_end_with(int argc, VALUE *argv, VALUE str)
{
int i;
- char *p, *s;
+ char *p, *s, *e;
rb_encoding *enc;
for (i=0; i<argc; i++) {
@@ -6293,8 +6293,9 @@ rb_str_end_with(int argc, VALUE *argv, VALUE str)
enc = rb_enc_check(str, tmp);
if (RSTRING_LEN(str) < RSTRING_LEN(tmp)) continue;
p = RSTRING_PTR(str);
- s = p + RSTRING_LEN(str) - RSTRING_LEN(tmp);
- if (rb_enc_left_char_head(p, s, enc) != s)
+ e = p + RSTRING_LEN(str);
+ s = e - RSTRING_LEN(tmp);
+ if (rb_enc_left_char_head(p, s, e, enc) != s)
continue;
if (memcmp(s, RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)
return Qtrue;