Each_char

e$B0J2<$N$h$&$K!"e(Beach_char e$B$,e(B “bc” e$B$H$+e(B
1e$BJ8;z$G$J$$$b$N$re(B yield
e$B$7$^$9!#e(B

% ./ruby -ve ‘s = “\xa4\xa2bc”.force_encoding(“euc-jp”); s.each_char
{|x| p x }’
ruby 1.9.0 (2008-01-19 revision 0) [i686-linux]
"e$B$“e(B”
“bc”
“c”

e$B%P%s%5%s$H?=$7$^$9!#e(B

On Jan 20, 2008, at 8:57 AM, Tanaka A. wrote:

e$B0J2<$N$h$&$K!"e(Beach_char e$B$,e(B “bc” e$B$H$+e(B 1e$BJ8e(B
e$B;z$G$J$$$b$N$re(B yield
e$B$7$^$9!#e(B

% ./ruby -ve ‘s = “\xa4\xa2bc”.force_encoding(“euc-jp”); s.each_char
{|x| p x }’
ruby 1.9.0 (2008-01-19 revision 0) [i686-linux]
"e$B$“e(B”
“bc”
“c”

e$BLdBj$OA0$N;z$ND9$5$,;H$o$l$F$$$?;v$G$9!#e(B
[email protected]$7$$;H$$J}$O$h$/$o$+$i$J$$$G$9$1$I0J2<$N%Q%Ce(B
e$B%[email protected]$9$k$_$?$$$G$9!#e(B

Index: string.c

— string.c (revision 15142)
+++ string.c (working copy)
@@ -4595,17 +4595,14 @@
rb_encoding *enc;

  RETURN_ENUMERATOR(str, 0, 0);
  • ptr = RSTRING_PTR(str);
    len = RSTRING_LEN(str);
  • enc = rb_enc_get(str);
  • n = rb_enc_mbclen(ptr, ptr + len, enc);
    for (i = 0; i < len; i += n) {
  • rb_yield(rb_str_subseq(str, i, n));
    ptr = RSTRING_PTR(str);
    len = RSTRING_LEN(str);
    enc = rb_enc_get(str);
    s = rb_enc_left_char_head(ptr, ptr + i, enc);
    n = rb_enc_mbclen(s, ptr + len, enc);
  • rb_yield(rb_str_subseq(str, i, n));
    }
    return str;
    }

e$B%P%s%5%s$H?=$7$^$9!#e(B

On Jan 20, 2008, at 9:42 AM, Vincent I. wrote:

“c”

e$BLdBj$OA0$N;z$ND9$5$,;H$o$l$F$$$?;v$G$9!#e(B
[email protected]$7$$;H$$J}$O$h$/$o$+$i$J$$$G$9$1$I0J2<$Ne(B
e$B%Q%C%[email protected]$9$k$_$?$$$G$9!#e(B

e$B$3$NA0$N%Q%C%A$Oe(Byielde$B$N8e$KJ8;zNs$ND9$5$r2~$a$F;29M$9$ke(B
e$B;v$rK:$l$F$$$^$7$?!#e(B
[email protected]$7$$%Q%C%A$O$3$N$h$&$G$9!'e(B

Index: string.c

— string.c (revision 15142)
+++ string.c (working copy)
@@ -4595,17 +4595,14 @@
rb_encoding *enc;

  RETURN_ENUMERATOR(str, 0, 0);
  • ptr = RSTRING_PTR(str);
    len = RSTRING_LEN(str);
  • enc = rb_enc_get(str);
  • n = rb_enc_mbclen(ptr, ptr + len, enc);
    for (i = 0; i < len; i += n) {
  • rb_yield(rb_str_subseq(str, i, n));
    ptr = RSTRING_PTR(str);
  • len = RSTRING_LEN(str);
    enc = rb_enc_get(str);
    s = rb_enc_left_char_head(ptr, ptr + i, enc);
    n = rb_enc_mbclen(s, ptr + len, enc);
  • rb_yield(rb_str_subseq(str, i, n));
  • len = RSTRING_LEN(str);
    }
    return str;
    }

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