[Feature #2571] 文字列のハミング距離

Feature #2571: e$BJ8;zNs$N%O%_%s%05wN%e(B
http://redmine.ruby-lang.org/issues/show/2571

e$B5/I<<Te(B: Kenta M.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core, Target version: 1.9.2

e$BJ8;zNs$N%O%%s%05wN%$r5a$a$k%a%=%C%I$,M$7$+$C$?$?$a!"e(BString#hamming_distance
e$B$r<BAu$7$^$7$?!#e(B
hamming_distance e$B$OD9$/$F;H$$$K$/$+$C$?$N$G!e(BString#^
e$B$bDj5A$7$^$7$?!#e(B
e$BJ8;z?t$,0[$J$k>l9g!$*$h$SHf3SIT2DG=$J%(%s%3!<%G%#%s%0$N>l9g$OL$Dj5A$H$7e(B
nil e$B$rJV$7$^$9!#e(B

e$B$3$l$,AH$9~$$G;HMQ$G$-$?$i0lHV4r$7$$$N$G$9$,!":[email protected]$/;v$O2DG=$G$7$g$&$+!)e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:39975] [Feature #2571]
e$BJ8;zNs$N%O%_%s%05wN%e(B
on Thu, 7 Jan 2010 17:06:10 +0900, Kenta M.
[email protected] writes:

|e$BJ8;zNs$N%O%%s%05wN%$r5a$a$k%a%=%C%I$,M$7$+$C$?$?$a!e(BString#hamming_distance e$B$r<BAu$7$^$7$?!#e(B
|hamming_distance e$B$OD9$/$F;H$$$K$/$+$C$?$N$G!e(BString#^ e$B$bDj5A$7$^$7$?!#e(B
|e$BJ8;z?t$,0[$J$k>l9g!$*$h$SHf3SIT2DG=$J%(%s%3!<%G%#%s%0$N>l9g$OL$Dj5A$H$7e(B nil e$B$rJV$7$^$9!#e(B
|
|e$B$3$l$,AH$9~$$G;HMQ$G$-$?$i0lHV4r$7$$$N$G$9$,!:[email protected]$/;v$O2DG=$G$7$g$&$+!)e(B

e$B2DG=$G$9$,!0J2<[email protected][email protected]$7$?>e!$H$$$&$3$H$K$J$k$Ge(B
e$B$7$g$&$M!#e(B

e$B%A%1%C%He(B #2571 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

e$B$3$N%a%=%C%I$re(B Ruby e$B$G<BAu$7$h$&$H$9$k$H!"e(BString#[] e$B$r;H$C$FHf3S$9$k$3$H$K$J$k$H;W$$$^$9!#e(B

String#codepoints e$B$r;H$&$H$$$&J}K!$,$"$j$^$9!#e(B
e$B$^$?!"$^$D$b$H$5$s$N$4;XE&$NDL$j3HD%%i%$%V%i%j$H$$$&J}K!$b$"$j$^$9$7!"e(Bgeme$B$G$b$$$$$G$7$g$&!#e(B

e$B%F%-%9%H=hM}[email protected][email protected]$+$i!"e(Btextutils
e$B$_$?$$$J%i%$%V%i%j$,E:IU$5$l$F$$$F$b$$$$5$$O$7$^$9$,!"e(B
e$BBEEv$K8+$($k%f!<%9%1!<%9$,$J$$$HFq$7$$$N$G$O$J$$$G$7$g$&$+!#e(B

http://redmine.ruby-lang.org/issues/show/2571

e$B%A%1%C%He(B #2571 e$B$,99?7$5$l$^$7$?!#e(B (by Kenta M.)

e$B$3$N%a%=%C%I$re(B Ruby e$B$G<BAu$7$h$&$H$9$k$H!"e(BString#[]
e$B$r;H$C$FHf3S$9$k$3$H$K$J$k$H;W$$$^$9!#e(B
e$B$=$N>l9g!"e(BString#[]
e$B$,8F$S=P$5$l$kEY$K?7$?$JJ8;zNs$,@8@.$5$l$F$7$^$$L5BL$J%%V%8%%/%H$,$$$/[email protected]@.$5$l$^$9!#e(B
e$BJ8;zNs$KBP$9$k%O%_%s%05wN%$N2r<a$,JQ2=$9$k$3$H$OKX$IL5$$$G$7$g$&$+$i!"e(B
e$BAH$9~$$N%a%=%C%I$H$7$F<BAu$5$l$F$$$kJ}$,0lHLE
$K4r$7$$$N$G$O$J$$$G$7$g$&$+!#e(B


http://redmine.ruby-lang.org/issues/show/2571

[email protected]@%$G$9!#e(B

(2010/01/11 15:35), Kenta M. wrote:

e$B$H$3$m$G!"3HD%%i%$%V%i%j$K$9$k:]$K!"e(Bstr_strlen e$B$r8x3+e(B API e$B$K$7$F$b$i$$$?$$$N$G$9$,!"e(B
e$B$=$l$O2DG=$G$7$g$&$+!)e(B rb_str_strlen e$B$K$J$k$N$+$J!)e(B

e$BL>A0$,$A$g$C$HG:$`=j$J$s$G$9$,$H$j$"$($:!"e(B

diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 14e23b85500a9e 100644
a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -662,6 +662,7 @@ VALUE rb_str_associated(VALUE);
void rb_str_setter(VALUE, ID, VALUE*);
VALUE rb_str_intern(VALUE);
VALUE rb_sym_to_s(VALUE);
+log rb_str_strlen(VALUE, rb_encoding*);
VALUE rb_str_length(VALUE);
long rb_str_offset(VALUE, long);
size_t rb_str_capacity(VALUE);
diff --git a/string.c b/string.c
index 2dcc3306a7d625 100644
a/string.c
+++ b/string.c
@@ -1033,8 +1033,8 @@ count_utf8_lead_bytes_with_word(const VALUE *s)
}
#endif

-static long
-str_strlen(VALUE str, rb_encoding *enc)
+long
+rb_str_strlen(VALUE str, rb_encoding *enc)
{
const char *p, *e;
long n;
@@ -1092,7 +1092,7 @@ rb_str_length(VALUE str)
{
long len;

  • len = str_strlen(str, STR_ENC_GET(str));
  • len = rb_str_strlen(str, STR_ENC_GET(str));
    return LONG2NUM(len);
    }

@@ -1573,11 +1573,11 @@ rb_str_substr(VALUE str, long beg, long len)
goto sub;
}
else {

  •  beg += str_strlen(str, enc);
    
  •  beg += rb_str_strlen(str, enc);
     if (beg < 0) return Qnil;
    
    }
    }
  • else if (beg > 0 && beg > str_strlen(str, enc)) {
  • else if (beg > 0 && beg > rb_str_strlen(str, enc)) {
    return Qnil;
    }
    if (len == 0) {
    @@ -2266,8 +2266,8 @@ rb_str_index(VALUE str, VALUE sub, long offset)
    if (is_broken_string(sub)) {
    return -1;
    }
  • len = str_strlen(str, enc);
  • slen = str_strlen(sub, enc);
  • len = rb_str_strlen(str, enc);
  • slen = rb_str_strlen(sub, enc);
    if (offset < 0) {
    offset += len;
    if (offset < 0) return -1;
    @@ -2329,7 +2329,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
    pos = 0;
    }
    if (pos < 0) {
  • pos += str_strlen(str, STR_ENC_GET(str));
  • pos += rb_str_strlen(str, STR_ENC_GET(str));
    if (pos < 0) {
    if (TYPE(sub) == T_REGEXP) {
    rb_backref_set(Qnil);
    @@ -2340,7 +2340,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)

    switch (TYPE(sub)) {
    case T_REGEXP:

  • if (pos > str_strlen(str, STR_ENC_GET(str)))
  • if (pos > rb_str_strlen(str, STR_ENC_GET(str)))
    return Qnil;
    pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
    rb_enc_check(str, sub), single_byte_optimizable(str));
    @@ -2382,8 +2382,8 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
    if (is_broken_string(sub)) {
    return -1;
    }
  • len = str_strlen(str, enc);
  • slen = str_strlen(sub, enc);
  • len = rb_str_strlen(str, enc);
  • slen = rb_str_strlen(sub, enc);
    /* substring longer than string */
    if (len < slen) return -1;
    if (len - pos < slen) {
    @@ -2433,7 +2433,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
    VALUE sub;
    VALUE vpos;
    rb_encoding *enc = STR_ENC_GET(str);
  • long pos, len = str_strlen(str, enc);
  • long pos, len = rb_str_strlen(str, enc);

    if (rb_scan_args(argc, argv, 11, &sub, &vpos) == 2) {
    pos = NUM2LONG(vpos);
    @@ -2981,7 +2981,7 @@ rb_str_aref(VALUE str, VALUE indx)
    long beg, len;
    VALUE tmp;

  •  len = str_strlen(str, STR_ENC_GET(str));
    
  •  len = rb_str_strlen(str, STR_ENC_GET(str));
     switch (rb_range_beg_len(indx, &beg, &len, len, 0)) {
       case Qfalse:
    

    break;
    @@ -3136,7 +3136,7 @@ rb_str_splice(VALUE str, long beg, long len, VALUE
    val)

    StringValue(val);
    enc = rb_enc_check(str, val);

  • slen = str_strlen(str, enc);
  • slen = rb_str_strlen(str, enc);

    if (slen < beg) {
    out_of_range:
    @@ -3232,14 +3232,14 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
    rb_raise(rb_eIndexError, string not matched);
    }
    beg = rb_str_sublen(str, beg);

  • rb_str_splice(str, beg, str_strlen(indx, 0), val);
  • rb_str_splice(str, beg, rb_str_strlen(indx, 0), val);
    return val;

    default:
    

    /* check if indx is Range */
    {
    long beg, len;

  •  if (rb_range_beg_len(indx, &beg, &len, str_strlen(str, 0), 2)) {
    
  •  if (rb_range_beg_len(indx, &beg, &len, rb_str_strlen(str, 0), 2)) 
    

{
rb_str_splice(str, beg, len, val);
return val;
}
@@ -6605,13 +6605,13 @@ rb_str_justify(int argc, VALUE *argv, VALUE str,
char jflag)
enc = rb_enc_check(str, pad);
f = RSTRING_PTR(pad);
flen = RSTRING_LEN(pad);

  • fclen = str_strlen(pad, enc);
  • fclen = rb_str_strlen(pad, enc);
    singlebyte = single_byte_optimizable(pad);
    if (flen == 0 || fclen == 0) {
    rb_raise(rb_eArgError, zero width padding);
    }
    }
  • len = str_strlen(str, enc);
  • len = rb_str_strlen(str, enc);
    if (width < 0 || len >= width) return rb_str_dup(str);
    n = width - len;
    llen = (jflag == l) ? 0 : ((jflag == r) ? n : n/2);
    @@ -6829,7 +6829,7 @@ rb_str_rpartition(VALUE str, VALUE sep)
    }
    return rb_ary_new3(3, rb_str_substr(str, 0, pos),
    sep,

rb_str_substr(str,pos+str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str)));
+
rb_str_substr(str,pos+rb_str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str)));
}

/*

e$B$`$i$?$G$9!#e(B

On 2010/01/07, at 17:35, Yukihiro M. wrote:

e$B$J$$$+!#e(B

e$B6D$kDL$j$G!"<B$O$3$l$+$i!JT=85wN%$bI,MW$K$J$k$3$H$,J,$+$C$F$$$^$9!#e(B
e$B$^$?!!V3HD%%i%$%V%i%[email protected]$o$l$k$H!"[email protected]$G$-$J$$$G$9$M!#e(B

e$B2~$a$F3HD%%i%$%V%i%j$H$7$FI8=`E:IU$7$F$b$i$($=$&$JF;$r9M$($F$_$h$&$H;W$$$^$9!#e(B

e$B$H$3$m$G!"3HD%%i%$%V%i%j$K$9$k:]$K!"e(Bstr_strlen e$B$r8x3+e(B API
e$B$K$7$F$b$i$$$?$$$N$G$9$,!"e(B
e$B$=$l$O2DG=$G$7$g$&$+!)e(B rb_str_strlen e$B$K$J$k$N$+$J!)e(B


Kenta M.
OpenPGP FP = FA26 35D7 4F98 3498 0810 E0D5 F213 966F E9EB 0BCC

e$BK$r=q$-$^$7$?e(B!!
e$B!Xe(BRuby e$B5U0z$-%l%7%T!Ye(B
http://www.amazon.co.jp/dp/4798119881/mrkn-22

E-mail: [email protected]
twitter: http://twitter.com/mrkn/
blog: http://d.hatena.ne.jp/mrkn/

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:40029] Re: [Feature #2571]
e$BJ8;zNs$N%O%_%s%05wN%e(B
on Mon, 11 Jan 2010 15:53:55 +0900, NARUSE, Yui
[email protected] writes:

|(2010/01/11 15:35), Kenta M. wrote:
|> e$B$H$3$m$G!"3HD%%i%$%V%i%j$K$9$k:]$K!"e(Bstr_strlen e$B$r8x3+e(B API e$B$K$7$F$b$i$$$?$$$N$G$9$,!e(B
|> e$B$=$l$O2DG=$G$7$g$&$+!)e(B rb_str_strlen e$B$K$J$k$N$+$J!)e(B
|
|e$BL>A0$,$A$g$C$HG:$`=j$J$s$G$9$,$H$j$$($:!"e(B

e$B8x3+$K$O;[email protected]$G$9!#$7$+$7!"e(Brb_str_strlen()e$B$H$9$k;~$K$O!"e(B

str_strlen(str, STR_ENC_GET(str))

e$B$rJV$9e(B1e$B0z?t$N4X?t$K$9$k$Y$-$G$O!#e(BVALUEe$B$rM?$($F$$$k$N$Ke(B
encodinge$B$b30$+$iEO$9I,MW$O$J$$$G$7$g$&!#e(B

[email protected]@%$G$9!#e(B

e$B%Q%C%A$,8m$C$F$$$^$7$?!"[email protected]$1$G$9$M!#e(B

diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 14e23b8116afa5 100644
a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -662,6 +662,7 @@ VALUE rb_str_associated(VALUE);
void rb_str_setter(VALUE, ID, VALUE*);
VALUE rb_str_intern(VALUE);
VALUE rb_sym_to_s(VALUE);
+long rb_str_strlen(VALUE);
VALUE rb_str_length(VALUE);
long rb_str_offset(VALUE, long);
size_t rb_str_capacity(VALUE);
diff --git a/string.c b/string.c
index 2dcc33078620b8 100644
a/string.c
+++ b/string.c
@@ -1079,6 +1079,12 @@ str_strlen(VALUE str, rb_encoding *enc)
return n;
}

+long
+rb_str_strlen(VALUE str)
+{

  • return str_strlen(str, STR_ENC_GET(str));
    +}

/*

  • call-seq:
  • str.length   => integer

[email protected]@%$G$9!#e(B

(2010/01/11 16:17), Yukihiro M. wrote:

e$B8x3+$K$O;[email protected]$G$9!#$7$+$7!"e(Brb_str_strlen()e$B$H$9$k;~$K$O!"e(B

str_strlen(str, STR_ENC_GET(str))

e$B$rJV$9e(B1e$B0z?t$N4X?t$K$9$k$Y$-$G$O!#e(BVALUEe$B$rM?$($F$$$k$N$Ke(B
encodinge$B$b30$+$iEO$9I,MW$O$J$$$G$7$g$&!#e(B

e$B3N$+$K!"[email protected]$7$^$7$?!#e(B

diff --git a/include/ruby/intern.h b/include/ruby/intern.h
index 14e23b8116afa5 100644
a/include/ruby/intern.h
+++ b/include/ruby/intern.h
@@ -662,6 +662,7 @@ VALUE rb_str_associated(VALUE);
void rb_str_setter(VALUE, ID, VALUE*);
VALUE rb_str_intern(VALUE);
VALUE rb_sym_to_s(VALUE);
+long rb_str_strlen(VALUE);
VALUE rb_str_length(VALUE);
long rb_str_offset(VALUE, long);
size_t rb_str_capacity(VALUE);
diff --git a/string.c b/string.c
index 2dcc330a4a6122 100644
a/string.c
+++ b/string.c
@@ -1079,6 +1079,12 @@ str_strlen(VALUE str, rb_encoding *enc)
return n;
}

+long
+rb_str_strlen(VALUE str)
+{

  • return rb_str_strlen(str, STR_ENC_GET(str));
    +}

/*

  • call-seq:
  • str.length   => integer
    

@@ -1092,7 +1098,7 @@ rb_str_length(VALUE str)
{
long len;

  • len = str_strlen(str, STR_ENC_GET(str));
  • len = rb_str_strlen(str, STR_ENC_GET(str));
    return LONG2NUM(len);
    }

@@ -1573,11 +1579,11 @@ rb_str_substr(VALUE str, long beg, long len)
goto sub;
}
else {

  •  beg += str_strlen(str, enc);
    
  •  beg += rb_str_strlen(str, enc);
     if (beg < 0) return Qnil;
    
    }
    }
  • else if (beg > 0 && beg > str_strlen(str, enc)) {
  • else if (beg > 0 && beg > rb_str_strlen(str, enc)) {
    return Qnil;
    }
    if (len == 0) {
    @@ -2266,8 +2272,8 @@ rb_str_index(VALUE str, VALUE sub, long offset)
    if (is_broken_string(sub)) {
    return -1;
    }
  • len = str_strlen(str, enc);
  • slen = str_strlen(sub, enc);
  • len = rb_str_strlen(str, enc);
  • slen = rb_str_strlen(sub, enc);
    if (offset < 0) {
    offset += len;
    if (offset < 0) return -1;
    @@ -2329,7 +2335,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)
    pos = 0;
    }
    if (pos < 0) {
  • pos += str_strlen(str, STR_ENC_GET(str));
  • pos += rb_str_strlen(str, STR_ENC_GET(str));
    if (pos < 0) {
    if (TYPE(sub) == T_REGEXP) {
    rb_backref_set(Qnil);
    @@ -2340,7 +2346,7 @@ rb_str_index_m(int argc, VALUE *argv, VALUE str)

    switch (TYPE(sub)) {
    case T_REGEXP:

  • if (pos > str_strlen(str, STR_ENC_GET(str)))
  • if (pos > rb_str_strlen(str, STR_ENC_GET(str)))
    return Qnil;
    pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
    rb_enc_check(str, sub), single_byte_optimizable(str));
    @@ -2382,8 +2388,8 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
    if (is_broken_string(sub)) {
    return -1;
    }
  • len = str_strlen(str, enc);
  • slen = str_strlen(sub, enc);
  • len = rb_str_strlen(str, enc);
  • slen = rb_str_strlen(sub, enc);
    /* substring longer than string */
    if (len < slen) return -1;
    if (len - pos < slen) {
    @@ -2433,7 +2439,7 @@ rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
    VALUE sub;
    VALUE vpos;
    rb_encoding *enc = STR_ENC_GET(str);
  • long pos, len = str_strlen(str, enc);
  • long pos, len = rb_str_strlen(str, enc);

    if (rb_scan_args(argc, argv, 11, &sub, &vpos) == 2) {
    pos = NUM2LONG(vpos);
    @@ -2981,7 +2987,7 @@ rb_str_aref(VALUE str, VALUE indx)
    long beg, len;
    VALUE tmp;

  •  len = str_strlen(str, STR_ENC_GET(str));
    
  •  len = rb_str_strlen(str, STR_ENC_GET(str));
     switch (rb_range_beg_len(indx, &beg, &len, len, 0)) {
       case Qfalse:
    

    break;
    @@ -3136,7 +3142,7 @@ rb_str_splice(VALUE str, long beg, long len, VALUE
    val)

    StringValue(val);
    enc = rb_enc_check(str, val);

  • slen = str_strlen(str, enc);
  • slen = rb_str_strlen(str, enc);

    if (slen < beg) {
    out_of_range:
    @@ -3232,14 +3238,14 @@ rb_str_aset(VALUE str, VALUE indx, VALUE val)
    rb_raise(rb_eIndexError, string not matched);
    }
    beg = rb_str_sublen(str, beg);

  • rb_str_splice(str, beg, str_strlen(indx, 0), val);
  • rb_str_splice(str, beg, rb_str_strlen(indx, 0), val);
    return val;

    default:
    

    /* check if indx is Range */
    {
    long beg, len;

  •  if (rb_range_beg_len(indx, &beg, &len, str_strlen(str, 0), 2)) {
    
  •  if (rb_range_beg_len(indx, &beg, &len, rb_str_strlen(str, 0), 2)) 
    

{
rb_str_splice(str, beg, len, val);
return val;
}
@@ -6605,13 +6611,13 @@ rb_str_justify(int argc, VALUE *argv, VALUE str,
char jflag)
enc = rb_enc_check(str, pad);
f = RSTRING_PTR(pad);
flen = RSTRING_LEN(pad);

  • fclen = str_strlen(pad, enc);
  • fclen = rb_str_strlen(pad, enc);
    singlebyte = single_byte_optimizable(pad);
    if (flen == 0 || fclen == 0) {
    rb_raise(rb_eArgError, zero width padding);
    }
    }
  • len = str_strlen(str, enc);
  • len = rb_str_strlen(str, enc);
    if (width < 0 || len >= width) return rb_str_dup(str);
    n = width - len;
    llen = (jflag == l) ? 0 : ((jflag == r) ? n : n/2);
    @@ -6829,7 +6835,7 @@ rb_str_rpartition(VALUE str, VALUE sep)
    }
    return rb_ary_new3(3, rb_str_substr(str, 0, pos),
    sep,

rb_str_substr(str,pos+str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str)));
+
rb_str_substr(str,pos+rb_str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str)));
}

/*

e$B:XF#$H?=$7$^$9!#0l2p$Ne(Blibrubye$B%f!<%6!<$G$9!#e(B

e$B%?%$%_%s%0$,0-$/[email protected]$KCY$l$F$7$^$$!"$4$a$s$J$5$$!#e(B

On Mon, 11 Jan 2010 16:35:19 +0900
Yukihiro M. [email protected] wrote:

e$B$=$&$G$9$M!#%3%_%C%H$7$F$/[email protected]$5$$!#e(B

e$B%3%_%C%H$5$l$F$7$^$C$?$h$&$G$9$,!"<+J,$O$"$^$j$h$$L>A0$G$J$$$H;W$$$^$9!#e(B

[email protected]$[$I8+$?$H$3$m$K$h$k$H!e(Brb_str_length()e$B$H$$$&!e(Brb_str_strlen()e$B$K$H$F$bNI$/;w$?e(B
e$B4X?t$,4{$K8x3+$5$l$F$$$k$h$&$G$7$?!#e(BC
APIe$B%f!<%6$J$i$P!$3$N$h$&$KL>A0$d0UL#$,;wDL$C$?e(B
e$B4X?t$,$$l$P!"$^$:$=$l$H$N0c$$$r0U<1$7$?$j!";~$K$O:.F1$7$?$j$9$k$3$H$,M=A[$G$-$^$9!#e(B

[email protected]$r4|$9$H!"e(Brb_str_length(str)e$B$He(BLONG2NUM(rb_str_strlen(str))e$B$OEy2A$J$h$&e(B
e$B$G$9!#$D$^$jN><T$N0c$$$O!e(BVALUEe$B$,JV$C$F$/$k$3$H$d!$=$NJQ49%3%9%H$,[email protected]$He(B
e$B;W$$$^$9!#e(B

e$B$3$N$h$&$J0UL#$N0c$$$,!e(B"length"e$B$He(B"strlen"e$B$H$$$&L>A0$N0c$$$GI=8=$G$-$F$$$k$H$O!<+J,e(B
e$B$K$O46$8$i$l$^$;$s!#$^$?e(Bstrlene$B$H$$$&$N$O!"$*$=$i$/e(Bstring
lengthe$B$NN,$G$"$j!e(B
[email protected]$$49$([email protected]$1$G$9$+$i!$d$O$j0UL#$N0c$$$OEA$o$i$J$$$N$G$Oe(B
e$B$J$$$G$7$g$&$+!#e(B

e$B$5$i$K$O!Ve(Bstrlen(3)e$B$H$$$&M-L>$Je(BCe$B$N4X?t$,$"[email protected]$+$i!e(Bfoo_strlen()e$B$H$$$&L>A0$re(B
e$BIU$1$l$P!JV$jCM$,e(BCe$B%M%$%F%#%V$G$$k;v$,N`?d$G$-$k$O$:[email protected]!W$H$$$&[email protected]$b$[email protected]$k$H;W$$e(B
e$B$^$9!#$7$+$7e(BCe$B$GM-L>$J4X?tL>$,!"$=$N$^$^e(BRubye$B$N%a%=%C%IL>$H$7$FB??t:NMQ$5$l$F$$$k$N$Oe(B
e$B;v<B$J$N$G!e(B(prefixe$B$rL5;k$7$?ItJ,$Ne(B)e$BL>A0$N$_$K$h$C$Fe(BRubye$B%l%$%d!<$He(BCe$B%l%$%d!<$r6hJL$9$ke(B
e$B$N$O$b$&:$Fq$G$7$g$&!#$h$C$F![email protected]$K$O$"$^[email protected]@NO$,$J$$$H9M$($^$9!#e(B

e$B$=$&$$$&$3$H$G<+J,$O!"e(Brb_str_strlen()e$B$h$j$b!Nc$($Pe(B
e$B!&e(Brb_str_length_long
(e$B7?$rL>A0$KKd$a9~$s$G$7$^$($PJ,$+$j$d$9$$$+$ie(B)
e$B!&e(Brb_str_length_raw (VALUEe$B$KJq$^[email protected][email protected]$+$ie(B)
e$B!&e(Brb_str_length_direct
(LONG2NUMe$B$H$$$&JQ49$rDL$5$J$$!VD>@[email protected]$+$ie(B)
e$B!&e(Brb_str_c_length (Ce$B$GD>@\07$($kCM$,JV$k$+$ie(B)
e$B$H$$$C$?$h$&$J!Ve(Brb_str_length +
e$B&A!W$NL>A0$NJ}$,K>$^$7$$$H;W$$$^$9$,!$I$&$Ge(B
e$B$7$g$&!#e(B

e$B$3$l$O!"4{B8$N4X?t$H0UL#$,;w$F$$$k$N$J$i$PL>A0$b;w$;$F!"0UL#$,0[$J$kItJ,$rL>A0$K$be(B
e$B:9J,$H$7$FH?1G$5$;$l$P!"e(BC
APIe$B%f!<%6$H$C$F$O$h$jJ,$+$j$d$9$/$J$k$H46$8$k$+$i$G$9!#e(B

e$B!D!D$H$$$&$h$&[email protected]$O!"e(BRubye$B$N%i%$%V%i%j$J$iF|>oCcHS;v$J$N$K!"e(BC
APIe$B$H$J$k$He(B

e$B$"$s$^$j$J$$$b$N$G$9$M!#e(B

e$B$b$C$H$b!"Kh2se(B len = NUM2LONG(rb_str_length(s))
e$B$H$+=q$/$N$O$?$7$+$K$A$g$C$He(B
e$BLLE]$/$5$$$G$9$7!B.EY$bB?>/Mn$A$F$7$^$&$H;W$&$N$G!$3$&$$$&4X?t$,8x3+$5$l$k;v<+BN$Oe(B
e$B;[email protected]$G$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:40033] Re: [Feature #2571]
e$BJ8;zNs$N%O%_%s%05wN%e(B
on Mon, 11 Jan 2010 16:32:21 +0900, NARUSE, Yui
[email protected] writes:

|e$B%Q%C%A$,8m$C$F$$$^$7$?!"[email protected]$1$G$9$M!#e(B

e$B$=$&$G$9$M!#%3%_%C%H$7$F$/[email protected]$5$$!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message Re: [ruby-dev:40038] str_strlen() e$B$N8x3+L>e(B (was Re:
Re: [Feature #2571] e$BJ8;zNs$N%O%_%s%05wN%e(B)
on Tue, 12 Jan 2010 01:14:08 +0900, Tadashi S.
[email protected] writes:

|e$B%3%_%C%H$5$l$F$7$^$C$?$h$&$G$9$,!"<+J,$O$"$^$j$h$$L>A0$G$J$$$H;W$$$^$9!#e(B
|
|[email protected]$[$I8+$?$H$3$m$K$h$k$H!e(Brb_str_length()e$B$H$$$&!e(Brb_str_strlen()e$B$K$H$F$bNI$/;w$?e(B
|e$B4X?t$,4{$K8x3+$5$l$F$$$k$h$&$G$7$?!#e(BC APIe$B%f!<%6$J$i$P!$3$N$h$&$KL>A0$d0UL#$,;wDL$C$?e(B
|e$B4X?t$,$$l$P!"$^$:$=$l$H$N0c$$$r0U<1$7$?$j!";~$K$O:.F1$7$?$j$9$k$3$H$,M=A[$G$-$^$9!#e(B

e$B$^$:!e(Brb_str_lengthe$B$He(Brb_str_strlene$B$N:[email protected]$,$$k$3$H$O!e(B
e$B$$kDxEYG$a$^$9!#$7$+$7!BeBX$G$$ke(B

|e$B$=$&$$$&$3$H$G<+J,$O!"e(Brb_str_strlen()e$B$h$j$b!Nc$($Pe(B
|e$B!&e(Brb_str_length_long (e$B7?$rL>A0$KKd$a9~$s$G$7$^$($PJ,$+$j$d$9$$$+$ie(B)
|e$B!&e(Brb_str_length_raw (VALUEe$B$KJq$^[email protected][email protected]$+$ie(B)
|e$B!&e(Brb_str_length_direct (LONG2NUMe$B$H$$$&JQ49$rDL$5$J$$!VD>@[email protected]$+$ie(B)
|e$B!&e(Brb_str_c_length (Ce$B$GD>@\07$($kCM$,JV$k$+$ie(B)
|e$B$H$$$C$?$h$&$J!Ve(Brb_str_length + e$B&A!W$NL>A0$NJ}$,K>$^$7$$$H;W$$$^$9$,!$I$&$Ge(B
|e$B$7$g$&!#e(B

e$B$O$$$:$l$bITI,MW$KD9$$$H46$8$^$9!#$N$G!">/$J$/$H$b$3$l$i$X$Ne(B
e$B2~L>$O;[email protected]$G$-$^$;$s!#e(B

[email protected]$($P!e(Bstrlene$B$H$$$&!Ve(BCe$B%i%$%V%i%j4X?t$NL>A0!W$O!$3$l$Oe(B
Ce$B$+$iD>@\8F$S=P$5$l$k4X?te(B(e$B$G$"$k$+$ie(Blonge$B$rJV$9e(B)e$B$3$H$rA[5/$5$;e(B
e$B$^$9!#$=$l$K4V0c$($F$b!"7?%A%%C%/$G0z$C$+$+$k$7!#e(B

[email protected]*[email protected][email protected]$i$7$$e(B(e$B6l>Pe(B

[email protected]@%$G$9!#e(B

2010/1/12 Yukihiro M. [email protected]:

e$B$^$:!e(Brb_str_lengthe$B$He(Brb_str_strlene$B$N:[email protected]$,$$k$3$H$O!e(B
e$B$$kDxEYG$a$^$9!#$7$+$7!BeBX$G$$ke(B

e$B$3$l$K4X$7$F$Oe(B libc e$B$N4X?tL>$J$N$G$$$$$+$J$H;W$C$F$$$^$9!#e(B

e$B$5$F$$-!"e(Bstring e$B$de(B encoding e$BMm$_$N4X?t$Oe(B rb_encoding
[email protected]$+!"$+$J$j:.Mp$7$?$j$O$7$^$7$?!#e(B
e$B35$M!0z?t$,e(BVALUEe$B$+H]$+!La$jCM$,e(BVALUEe$B$+H]$+$Ge(B4e$BDL$j$K$J$k$N$G!e(B
e$B$$$$L?L>5,B$,$$l$P$$$$$J$!$H;W$C$?$j$O$7$^$9!#e(B
VALUE rbvv_str_length(VALUE);
long rbvc_str_length(VALUE);
e$B$J$I$HLQA[$7$?$j$7$D$D!$3$l$b$J$s$+$J$!!$H$+!#e(B

e$B%A%1%C%He(B #2571 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

e$B1sF#$G$9!#e(B

e$BK\7o$ODs0F<T$Ne(B mrkn e$B$5$s$,0lC6<h$j2<$2$?$h$&$J$N$Ge(B
([ruby-dev:40028]) e$B!"e(B
closed e$B$H$7$^$9!#e(B


Yusuke E. [email protected]

http://redmine.ruby-lang.org/issues/show/2571

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs