mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
8984fa6742
commit
bf2d82b280
2 changed files with 7 additions and 11 deletions
|
@ -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>
|
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,
|
* enc/{euc_jp.c,gbk.c,iso_8859_1.c,iso_8859_11.c,iso_8859_13.c,
|
||||||
|
|
14
string.c
14
string.c
|
@ -1071,19 +1071,11 @@ str_utf8_offset(const char *p, const char *e, int nth)
|
||||||
static long
|
static long
|
||||||
str_sublen(VALUE str, long pos, rb_encoding *enc)
|
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 {
|
else {
|
||||||
char *p = RSTRING_PTR(str);
|
char *p = RSTRING_PTR(str);
|
||||||
char *e = p + pos;
|
return rb_enc_strlen(p, p + pos, enc);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue