aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--string.c14
2 files changed, 7 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 5bcd0ab78d..b37fc4652e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Feb 17 13:03:48 2008 Tanaka Akira <akr@fsij.org>
+
+ * string.c (str_sublen): use rb_enc_strlen.
+
Sun Feb 17 12:17:52 2008 NARUSE, Yui <naruse@ruby-lang.org>
* enc/{euc_jp.c,gbk.c,iso_8859_1.c,iso_8859_11.c,iso_8859_13.c,
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);
}
}