зеркало из https://github.com/github/ruby.git
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
This commit is contained in:
Родитель
30f008a8e3
Коммит
1a95e46cc6
|
@ -1,3 +1,9 @@
|
|||
Tue Jul 22 12:56:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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]
|
||||
|
||||
Tue Jul 22 01:48:38 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* include/ruby/io.h (rb_io_buffer_t): fix packing on gcc
|
||||
|
|
6
string.c
6
string.c
|
@ -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);
|
||||
|
|
|
@ -1037,6 +1037,11 @@ class TestM17N < Test::Unit::TestCase
|
|||
assert_raise(Encoding::CompatibilityError){s.count(a("\xa3\xb0"))}
|
||||
end
|
||||
|
||||
def test_count_sjis_trailing_byte
|
||||
bug10078 = '[ruby-dev:48442] [Bug #10078]'
|
||||
assert_equal(0, s("\x98\x61").count("a"), bug10078)
|
||||
end
|
||||
|
||||
def test_delete
|
||||
assert_equal(1, e("\xa1\xa2").delete("z").length)
|
||||
s = e("\xa3\xb0\xa3\xb1\xa3\xb2\xa3\xb3\xa3\xb4")
|
||||
|
|
Загрузка…
Ссылка в новой задаче