From: sekita-n@... (Nobutaka SEKITANI) Date: 2000-04-01T12:32:15+09:00 Subject: [ruby-list:21717] patch of `Support for strings represented as a vector of ordinals' Perl5.6の Support for strings represented as a vector of ordinals すなわち v1.2.3 が "\001\002\003" に変換される機能をrubyに追加するパッ チを書いてみました。 ただしrubyの文法上、 %v1.2.3 というふうに書くことになります。 Perl5.6を実際に使用せず、ソースもろくに見ずに作ったシロモノですので、 Perl5.6のとは挙動が異なるかもしれません。 ruby-1.4.3へのパッチの形になっていますが、1.5.3でもトラブルなく当てら れました。 パッチはsignatureの下にあり、 % cd ruby-1.4.3/ % patch -p1 < this-patch で当てられます。 --- 電気通信大学大学院 情報システム学研究科 2年 |% 予習 関谷 信貴(せきたに のぶたか) |file system full. e-mail sekita-n@hera.im.uec.ac.jp |% 授業 Webpage http://pluto.im.uec.ac.jp/~sekita-n/ |file system full.;_; ↑Do you know `Little Master'? |system downed... ------ Cut here ------ diff -ur ruby-1.4.3/parse.y ruby-1.4.3-new/parse.y --- ruby-1.4.3/parse.y Sat Apr 1 11:58:34 2000 +++ ruby-1.4.3-new/parse.y Sat Apr 1 11:57:44 2000 @@ -2473,6 +2473,53 @@ double strtod (); #endif +static int parse_version_text(); + +static int +parse_version_text() +{ + VALUE verstr = rb_str_new("", 0); + register int c; + int i = 0; + int c1idx = 0; + unsigned char c1[16]; + + for(;;){ + c = nextc(); + + if(!ISDIGIT(c)){ + rb_compile_error("invalid version text"); + } + + while(ISDIGIT(c)){ + i *= 10; + i += c - '0'; + c = nextc(); + } + + c1[c1idx] = (unsigned char)i; + c1idx++; + + switch(c){ + case '.': + if(c1idx == 16){ + rb_str_cat(verstr, c1, 16); + c1idx = 0; + } + i = 0; + break; + + default: + rb_str_cat(verstr, c1, c1idx); + pushback(c); + yylval.val = verstr; + + return(tSTRING); + } + } +} + + static int yylex() { @@ -3043,6 +3090,9 @@ if (!ISALNUM(c)) { term = c; c = 'Q'; + } + else if(c == 'v'){ /* Perl-5.6 feature */ + return parse_version_text(); } else { term = nextc();