From cd50451ec7fb0c4a0c6d47eb1f696c334f9f5a93 Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 17 Feb 2008 04:04:14 +0000 Subject: * string.c (str_sublen): use rb_enc_strlen. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index cc39d7269..aef3d1896 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); } } -- cgit