summaryrefslogtreecommitdiffstats
path: root/string.c
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
commitb6e956564620ee1d851e41c33dbf97dbcea5d80d (patch)
treef11be1c581b236746c37c811bf9a858fa5491b3d /string.c
parent6084564c57f5814feedc68b4a796a4f164177da1 (diff)
downloadruby-b6e956564620ee1d851e41c33dbf97dbcea5d80d.tar.gz
ruby-b6e956564620ee1d851e41c33dbf97dbcea5d80d.tar.xz
ruby-b6e956564620ee1d851e41c33dbf97dbcea5d80d.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@15700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/string.c b/string.c
index 79288ceeb..89a8b465f 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) {