diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-22 03:56:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-07-22 03:56:26 +0000 |
commit | 1a95e46cc6194933cf75a4bf91a0bb6502f177a0 (patch) | |
tree | 9d5404fbb87c658942acae26830475e633f793b3 /string.c | |
parent | 30f008a8e383f20e907ecd9c5f449f64d10eb6dc (diff) | |
download | ruby-1a95e46cc6194933cf75a4bf91a0bb6502f177a0.tar.gz |
string.c: fix wrong single-byte optimization
* string.c (rb_str_count): fix wrong single-byte optimization.
7bit ascii can be a trailing byte in Shift_JIS.
[ruby-dev:48442] [Bug #10078]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -6075,13 +6075,15 @@ rb_str_count(int argc, VALUE *argv, VALUE str) rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); for (i=0; i<argc; i++) { VALUE tstr = argv[i]; - unsigned char c; + const unsigned char *utstr; StringValue(tstr); enc = rb_enc_check(str, tstr); if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) && - (c = RSTRING_PTR(tstr)[0]) < 0x80 && !is_broken_string(str)) { + (utstr = (const OnigUChar *)RSTRING_PTR(tstr), ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, utstr, utstr+1)) && + !is_broken_string(str)) { int n = 0; + unsigned char c = utstr[0]; s = RSTRING_PTR(str); if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0); |