summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-17 04:04:14 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-17 04:04:14 +0000
commitbf2d82b280af0c2327a939013699a4616fa5c1c1 (patch)
tree67538587d44b000f9311850e3fafb4df375ba9ba /string.c
parent8984fa674290c17b62c7cf5cf0dd266d297fc14b (diff)
* string.c (str_sublen): use rb_enc_strlen.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/string.c b/string.c
index cc39d7269a..aef3d1896c 100644
--- a/string.c
+++ b/string.c
@@ -1071,19 +1071,11 @@ str_utf8_offset(const char *p, const char *e, int nth)
static long
str_sublen(VALUE str, long pos, rb_encoding *enc)
{
- if (rb_enc_mbmaxlen(enc) == 1 || pos < 0) return pos;
+ if (rb_enc_mbmaxlen(enc) == 1 || pos < 0)
+ return pos;
else {
char *p = RSTRING_PTR(str);
- char *e = p + pos;
- long i;
-
- i = 0;
- while (p < e) {
- p += rb_enc_mbclen(p, RSTRING_END(str), enc);
- i++;
- }
- if (p == e) return i;
- return i - 1;
+ return rb_enc_strlen(p, p + pos, enc);
}
}