Rb_eval_string_protect and encoding

e$B=uED$G$9!#e(B

rb_eval_string_protect e$B$He(B Encoding e$B$K4X$9$k<ALd$G$9!#e(B

e$B<!$N%=!<%9$N<B9T7k2L$N:G8e$N9T$re(B

#Encoding:EUC-JP

e$B$H$9$k$?$a$K$O!"$I$&$9$l$P$$$$$s$G$7$g$&$+!)e(B
rb_eval_string_protect
e$B$KEO$9J8;zNs$NCf$Ke(Beuc-jpe$B$NJ8;zNs$,4^$^$l$F$$$ke(B
e$B$H$-!"$=$l$,e(B euc-jp
e$B$N%9%/%j%W%H$H$7$FI>2A$7$F$b$i$&$K$O$I$&$9$l$P$$$$e(B
e$B$N$G$7$g$&$+!)e(B

/*

  • e$B$3$N%=!<%9%U%!%$%k<+BN$Ne(BEncoding e$B$Oe(Beuc-jp
    */
    #include <stdio.h>
    #include <ruby.h>
    #include <ruby/encoding.h>
    int main(int argc, char ** argv) {
    int state = 0;
    rb_encoding *enc;
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();
    rb_enc_find_index(“encdb”);
    rb_eval_string_protect(“puts RUBY_DESCRIPTION”, &state);
    rb_eval_string_protect(“p Encoding.default_internal”, &state);
    enc = rb_enc_find(“euc-jp”);
    if(enc) {
    rb_enc_set_default_internal(rb_enc_from_encoding(enc));
    }
    rb_eval_string_protect(“p Encoding.default_internal”, &state);
    rb_eval_string_protect(“p 'e$B$”$$$&$($e(B’.encoding", &state);
    return 0;
    }
    /

    e$B<B9T7k2Le(B
    ruby 1.9.2dev (2009-07-24 trunk 24264) [i686-linux]
    nil
    #Encoding:EUC-JP
    #Encoding:ASCII-8BIT
    */

e$B=uEDe(B e$B2m5*e(B

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

At Sat, 25 Jul 2009 15:43:04 +0900,
Masaki S. wrote in [ruby-dev:38900]:

e$B<!$N%=!<%9$N<B9T7k2L$N:G8e$N9T$re(B

#Encoding:EUC-JP

e$B$H$9$k$?$a$K$O!"$I$&$9$l$P$$$$$s$G$7$g$&$+!)e(B
rb_eval_string_protect e$B$KEO$9J8;zNs$NCf$Ke(Beuc-jpe$B$NJ8;zNs$,4^$^$l$F$$$ke(B
e$B$H$-!"$=$l$,e(B euc-jp e$B$N%9%/%j%W%H$H$7$FI>2A$7$F$b$i$&$K$O$I$&$9$l$P$$$$e(B
e$B$N$G$7$g$&$+!)e(B

e$B8=>u$G$Oe(BStringe$B$re(Bevale$B$9$k4X?t$ODs6!$5$l$F$$$J$$$N$G!"e(Bmagic
commente$B$rKd$a9~$`$/$i$$$7$+$J$$$G$9$M!#e(B

rb_eval_string_protect("#-*- coding: euc-jp -*-\n" "p 

‘e$B$"$$$&$($*e(B’.encoding", &state);

e$B?7$7$$4X?t$rDI2C$9$k$H$7$?$i!"$I$s$JL>A0$,$$$$$G$7$g$&$M$’!#e(B

e$B=uED$G$9!#e(B

Nobuyoshi N. wrote:

rb_eval_string_protect e$B$KEO$9J8;zNs$NCf$Ke(Beuc-jpe$B$NJ8;zNs$,4^$^$l$F$$$ke(B
e$B$H$-!"$=$l$,e(B euc-jp e$B$N%9%/%j%W%H$H$7$FI>2A$7$F$b$i$&$K$O$I$&$9$l$P$$$$e(B
e$B$N$G$7$g$&$+!)e(B

e$B8=>u$G$Oe(BStringe$B$re(Bevale$B$9$k4X?t$ODs6!$5$l$F$$$J$$$N$G!"e(Bmagic
commente$B$rKd$a9~$`$/$i$$$7$+$J$$$G$9$M!#e(B

rb_eval_string_protect("#-*- coding: euc-jp -*-\n" "p 'e$B$"$$$&$($*e(B'.encoding", &state);

e$B$J$k$[$I!"%@%$%l%/%H$K$=$&$d$k$7$+$J$$$s$G$9$M!#e(B

e$B?7$7$$4X?t$rDI2C$9$k$H$7$?$i!"$I$s$JL>A0$,$$$$$G$7$g$&$M$’!#e(B

e$B$&!<$s!#2?$,$$$$$s$G$7$g$&$M!#e(B
rb_eval_vstring_protecte$B$H$+!)e(B

rb_eval_string_protecte$B$r;H$&$H$9$k$H$3$s$J46$8$G$9$+!)e(B
e$B!J%(%i!<%A%’%C%/$,4E$$$+$b!Ke(B
VALUE rb_eval_vstring_protect(VALUE s, int state) {
char encname;
VALUE v;
encname = rb_enc_name(rb_enc_get(s));
v = rb_sprintf("#-
- coding:%s-
-\n%s", encname, StringValuePtr(s));
return rb_eval_string_protect(StringValuePtr(v), state);
}

e$B=uEDe(B e$B2m5*e(B

e$B=uED$G$9!#e(B

Nobuyoshi N. wrote:

e$B$$$d!"e(BStringe$B$J$i$9$G$Ke(BEncodinge$B$r;}$C$F$$$k$N$G!“e(Bmagic commente$B$re(B
e$BDI2C$9$kI,MW$O$”$j$^$;$s!#[email protected]$+$i$3$=!“e(BStringe$B%P!<%8%g%s$,$”$l$P2re(B
e$B7h$9$k$N$+$J$H$$$&$3$H$G$9!#e(B

e$B$J$k$[$I!#e(Bmagic comment e$B$OITMW$J$s$G$9$M!#e(B
e$B5U$K$D$$$F$$$?$j$9$k$H$^$:$$$s$G$7$g$&$+!)e(B

e$B2>$Ke(B magic comment e$B$,e(B String object
e$B$K4^$^$l$F$$$F!“e(BString object
e$B$Ne(B encoding e$B$H0lCW$7$F$$$J$$$H$-$O!”$^$:$$$s$G$9$+$M!#e(B
e$B$=$l$H$be(B magic comment e$B$,M%@h$5$l$k$G$7$g$&$+!)e(B

e$B$H$$$&$+$I$&$$$&5sF0$,!“e(BRubye$B$rB>$N%”%W%j$KAH$_9~$>l9g$KET9g$,$h$$e(B e$B$N$+<+J,$G$b$h$/$o$+$i$J$$e(B... e$BAH$_9~$%"%W%j<!Bh$+$J!#e(B

e$B>/$J$/$H$be(B encoding e$B$,2?$i$+$N7A$G;XDj$G$-$ke(B rb_eval
e$B7Oe(B e$B$Ne(B API e$B$,e(B
e$B$"$C$?J}$,4r$7$$$H;W$$$^$9!#e(B

e$B=uEDe(B e$B2m5*e(B

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

At Sat, 25 Jul 2009 23:00:13 +0900,
Masaki S. wrote in [ruby-dev:38904]:

rb_eval_string_protecte$B$r;H$&$H$9$k$H$3$s$J46$8$G$9$+!)e(B
e$B!J%(%i!<%A%’%C%/$,4E$$$+$b!Ke(B
VALUE rb_eval_vstring_protect(VALUE s, int state) {
char encname;
VALUE v;
encname = rb_enc_name(rb_enc_get(s));
v = rb_sprintf("#-
- coding:%s-
-\n%s", encname, StringValuePtr(s));
return rb_eval_string_protect(StringValuePtr(v), state);
}

e$B$$$d!"e(BStringe$B$J$i$9$G$Ke(BEncodinge$B$r;}$C$F$$$k$N$G!“e(Bmagic
commente$B$re(B
e$BDI2C$9$kI,MW$O$”$j$^$;$s!#[email protected]$+$i$3$=!“e(BStringe$B%P!<%8%g%s$,$”$l$P2re(B
e$B7h$9$k$N$+$J$H$$$&$3$H$G$9!#e(B

VALUE
rb_eval_vstring(VALUE str)
{
return eval_string(rb_vm_top_self(), str, Qnil, “(eval)”, 1);
}

VALUE
rb_eval_vstring_protect(VALUE str, int *state)
{
return rb_protect(rb_eval_vstring, str, state);
}

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

At Sun, 26 Jul 2009 21:05:58 +0900,
Masaki S. wrote in [ruby-dev:38907]:

e$B2>$Ke(B magic comment e$B$,e(B String object e$B$K4^$^$l$F$$$F!“e(BString object
e$B$Ne(B encoding e$B$H0lCW$7$F$$$J$$$H$-$O!”$^$:$$$s$G$9$+$M!#e(B
e$B$=$l$H$be(B magic comment e$B$,M%@h$5$l$k$G$7$g$&$+!)e(B

magic commente$B$,M%@h$5$l$^$9!#e(B

e$B$H$$$&$+$I$&$$$&5sF0$,!“e(BRubye$B$rB>$N%”%W%j$KAH$_9~$>l9g$KET9g$,$h$$e(B e$B$N$+<+J,$G$b$h$/$o$+$i$J$$e(B... e$BAH$_9~$%"%W%j<!Bh$+$J!#e(B

e$B>/$J$/$H$be(B encoding e$B$,2?$i$+$N7A$G;XDj$G$-$ke(B rb_eval e$B7Oe(B e$B$Ne(B API e$B$,e(B
e$B$"$C$?J}$,4r$7$$$H;W$$$^$9!#e(B

rb_encoding*
e$B$^$?$O%(%s%3!<%G%#%s%0L>$r;XDj$9$kI,MW$,$"$ke(BAPIe$B$H$+!"e(B
Stringe$B$r;H$&$b$N$H$+$/$i$$$7$+;W$$$D$-$^$;$s$,!“B>$K2?$+%”%$%G%“e(B
e$B$”$j$^$9$+!#e(B

e$B=uED$G$9!#e(B

Nobuyoshi N. wrote:

e$B2>$Ke(B magic comment e$B$,e(B String object e$B$K4^$^$l$F$$$F!“e(BString object
e$B$Ne(B encoding e$B$H0lCW$7$F$$$J$$$H$-$O!”$^$:$$$s$G$9$+$M!#e(B
e$B$=$l$H$be(B magic comment e$B$,M%@h$5$l$k$G$7$g$&$+!)e(B

magic commente$B$,M%@h$5$l$^$9!#e(B

e$B$J$k$[$I!#9M$($F$_$l$P!"$=$l$,0lHV<+A3$J5$$,$7$^$9!#e(B

e$B>/$J$/$H$be(B encoding e$B$,2?$i$+$N7A$G;XDj$G$-$ke(B rb_eval e$B7Oe(B e$B$Ne(B API e$B$,e(B
e$B$"$C$?J}$,4r$7$$$H;W$$$^$9!#e(B

rb_encoding* e$B$^$?$O%(%s%3!<%G%#%s%0L>$r;XDj$9$kI,MW$,$"$ke(BAPIe$B$H$+!"e(B
Stringe$B$r;H$&$b$N$H$+$/$i$$$7$+;W$$$D$-$^$;$s$,!“B>$K2?$+%”%$%G%“e(B
e$B$”$j$^$9$+!#e(B

e$B$$$(!#;d$b$=$Ne(B2e$B$D$0$i$$$7$+;W$$$D$-$^$;$s!#e(B

e$B=uEDe(B e$B2m5*e(B

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