aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-05 19:34:15 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-05 19:34:15 +0000
commit98cbcf1bd7909306d2ba542aaff2eceb71ccb5c1 (patch)
treef11be1c581b236746c37c811bf9a858fa5491b3d
parent579f16d9851fc220a1dda9a0d65e611cc37aeb14 (diff)
downloadruby-98cbcf1bd7909306d2ba542aaff2eceb71ccb5c1.tar.gz
* string.c (count_utf8_lead_bytes_with_ulong): fix shift size.
[ruby-dev:33993] * string.c (str_utf8_nth) fix wrong counting. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog17
-rw-r--r--string.c7
-rw-r--r--test/ruby/test_m17n.rb11
-rw-r--r--test/ruby/test_regexp.rb7
4 files changed, 28 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 00aad39c73..e289a15b78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Mar 6 04:32:06 2008 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * string.c (count_utf8_lead_bytes_with_ulong): fix shift size.
+ [ruby-dev:33993]
+
+ * string.c (str_utf8_nth) fix wrong counting.
+
Thu Mar 6 00:34:00 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* sprintf.c (rb_str_format): size_t returned from strlen() can be
@@ -7,7 +14,7 @@ Thu Mar 6 00:31:39 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* struct.c (make_struct): preserve encoding of struct name.
-Wed Mar 05 22:49:20 2008 NARUSE, Yui <naruse@ruby-lang.org>
+Wed Mar 5 22:49:20 2008 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (is_utf8_lead_byte, count_utf8_lead_bytes_with_ulong):
defined for UTF-8 optimization.
@@ -22,7 +29,7 @@ Wed Mar 5 17:53:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_flock): returns false on EAGAIN if non-blocking.
[ruby-core:15795]
-Web Mar 5 17:43:43 2008 Martin Duerst <duerst@it.aoyama.ac.jp>
+Wed Mar 5 17:43:43 2008 Martin Duerst <duerst@it.aoyama.ac.jp>
* transcode.c (transcode_loop): Adjusted detection of invalid
(ill-formed) UTF-8 sequences. Fixing potential security issue, see
@@ -85,7 +92,7 @@ Tue Mar 4 16:29:06 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (parser_yylex): disallow non digits '0o' expression.
-Tue Mar 04 14:35:12 2008 NARUSE, Yui <naruse@ruby-lang.org>
+Tue Mar 4 14:35:12 2008 NARUSE, Yui <naruse@ruby-lang.org>
* io.c (open_key_args): use rb_io_open_with_args instead of rb_f_open.
[ruby-core:15763]
@@ -99,7 +106,7 @@ Tue Mar 4 10:21:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (add_heap): use binary search to find the place to insert the
new heap slot. [ruby-dev:33983]
-Tue Mar 04 05:30:31 2008 NARUSE, Yui <naruse@ruby-lang.org>
+Tue Mar 4 05:30:31 2008 NARUSE, Yui <naruse@ruby-lang.org>
* io.c (open_key_args): use rb_io_open instead of rb_f_open.
[ruby-core:15746]
@@ -189,7 +196,7 @@ Sat Mar 1 12:15:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* thread.c (remove_event_hook): should not access freed memory.
[ruby-dev:31820]
-Sat Mar 01 10:31:19 2008 NARUSE, Yui <naruse@ruby-lang.org>
+Sat Mar 1 10:31:19 2008 NARUSE, Yui <naruse@ruby-lang.org>
* io.c (read_all, rb_io_getline_fast): encoding is io_input_encoding.
diff --git a/string.c b/string.c
index 79288ceeb2..89a8b465f2 100644
--- a/string.c
+++ b/string.c
@@ -763,7 +763,7 @@ count_utf8_lead_bytes_with_ulong(const unsigned long *s)
unsigned long d = *s;
d |= ~(d>>1);
d >>= 6;
- d &= NONASCII_MASK >> 3;
+ d &= NONASCII_MASK >> 7;
d += (d>>8);
d += (d>>16);
#if NONASCII_MASK == 0x8080808080808080UL
@@ -1177,11 +1177,10 @@ str_utf8_nth(const char *p, const char *e, int nth)
if (is_utf8_lead_byte(*p)) nth--;
p++;
}
- while (s < t) {
+ do {
nth -= count_utf8_lead_bytes_with_ulong(s);
- if (nth < sizeof(long)) break;
s++;
- }
+ } while (s < t && sizeof(long) <= nth);
p = (char *)s;
}
if (0 < nth) {
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 069554a127..7a9e24f4a1 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -810,6 +810,17 @@ class TestM17N < Test::Unit::TestCase
assert_equal(false, str[0..-1].ascii_only?)
end
+ def test_utf8str_aref
+ s = "abcdefghijklmnopqrstuvwxyz\u{3042 3044 3046 3048 304A}"
+ assert_equal("a", s[0])
+ assert_equal("h", s[7])
+ assert_equal("i", s[8])
+ assert_equal("j", s[9])
+ assert_equal("\u{3044}", s[27])
+ assert_equal("\u{3046}", s[28])
+ assert_equal("\u{3048}", s[29])
+ end
+
def test_str_aref_len
assert_equal(a("\xa1"), a("\xc2\xa1\xc2\xa2\xc2\xa3")[1, 1])
assert_equal(a("\xa1\xc2"), a("\xc2\xa1\xc2\xa2\xc2\xa3")[1, 2])
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 29783d4153..17fe9fa45f 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -123,6 +123,8 @@ class TestRegexp < Test::Unit::TestCase
r = /./
m = r.match("a")
assert_equal(r, m.regexp)
+ re = /foo/
+ assert_equal(re, re.match("foo").regexp)
end
def test_source
@@ -188,11 +190,6 @@ class TestRegexp < Test::Unit::TestCase
assert_equal(/foo/, m.dup.regexp)
end
- def test_match_regexp
- re = /foo/
- assert_equal(re, re.match("foo").regexp)
- end
-
def test_match_size
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
assert_equal(5, m.size)