Skip to content

Commit

Permalink
* string.c (rb_str_index): check if substring is broken.
Browse files Browse the repository at this point in the history
* string.c (rb_str_rindex): ditto.

* string.c (rb_str_succ): should carry over.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
matz committed Dec 17, 2007
1 parent b2d9f1e commit ea1b9d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Mon Dec 17 17:50:30 2007 Yukihiro Matsumoto <matz@ruby-lang.org>

* string.c (rb_str_index): check if substring is broken.

* string.c (rb_str_rindex): ditto.

* string.c (rb_str_succ): should carry over.

Mon Dec 17 17:47:26 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* common.mk (encs): new target to compile external encodings.
Expand Down
8 changes: 4 additions & 4 deletions bootstraptest/test_knownbug.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ def m() yield nil,[] end
"\xa1\xa2\xa3\xa4".force_encoding("euc-jp").include?("\xa3".force_encoding("euc-jp"))
}

assert_equal 'nil', %q{
"\xa1\xa2\xa3\xa4".force_encoding("euc-jp").index("\xa3".force_encoding("euc-jp"))
assert_equal 'ok', %q{
"\xa1\xa2\xa3\xa4".force_encoding("euc-jp").index("\xa3".force_encoding("euc-jp")) or :ok
}

assert_equal 'nil', %q{
"\xa1\xa2\xa3\xa4".force_encoding("euc-jp").rindex("\xa3".force_encoding("euc-jp"))
assert_equal 'ok', %q{
"\xa1\xa2\xa3\xa4".force_encoding("euc-jp").rindex("\xa3".force_encoding("euc-jp")) or :ok
}

assert_equal 'false', %q{
Expand Down
3 changes: 2 additions & 1 deletion encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc)
return n;
}

int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
int
rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc)
{
int c, l;
if (e <= p)
Expand Down
9 changes: 8 additions & 1 deletion string.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ VALUE rb_cSymbol;

#define is_ascii_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
#define IS_7BIT(str) (ENC_CODERANGE(str) == ENC_CODERANGE_7BIT)
#define is_broken_string(str) (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN)

VALUE rb_fs;

Expand Down Expand Up @@ -1443,6 +1444,9 @@ rb_str_index(VALUE str, VALUE sub, long offset)
rb_encoding *enc;

enc = rb_enc_check(str, sub);
if (is_broken_string(sub)) {
return -1;
}
len = str_strlen(str, enc);
slen = str_strlen(sub, enc);
if (offset < 0) {
Expand Down Expand Up @@ -1553,6 +1557,9 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
int asc = IS_7BIT(str);

enc = rb_enc_check(str, sub);
if (is_broken_string(sub)) {
return -1;
}
len = str_strlen(str, enc);
slen = str_strlen(sub, enc);
/* substring longer than string */
Expand Down Expand Up @@ -1863,7 +1870,7 @@ rb_str_succ(VALUE orig)
if (c == -1) { /* str contains no alnum */
c = '\001';
s = e;
while ((s = rb_enc_prev_char(sbeg, e, enc)) != 0) {
while ((s = rb_enc_prev_char(sbeg, s, enc)) != 0) {
if (cc == 0) cc = rb_enc_codepoint(s, e, enc);
cc += 1;
l = rb_enc_mbcput(cc, carry, enc);
Expand Down

0 comments on commit ea1b9d5

Please sign in to comment.