[#32498] Re: [ruby-cvs:21399] Ruby:r14162 (trunk): * parse.y (expr): redefinable not (!) operator. — SASADA Koichi <ko1@...>

 ささだです.

9 messages 2007/12/09

[#32512] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Nobuyoshi Nakada <nobu@...>

なかだです。

33 messages 2007/12/10
[#32520] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Martin Duerst <duerst@...> 2007/12/10

中田さん、こんにちは。

[#32527] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Nobuyoshi Nakada <nobu@...> 2007/12/10

なかだです。

[#32535] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Yukihiro Matsumoto <matz@...> 2007/12/11

まつもと ゆきひろです

[#32537] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Martin Duerst <duerst@...> 2007/12/11

At 15:33 07/12/11, Yukihiro Matsumoto wrote:

[#32538] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Yukihiro Matsumoto <matz@...> 2007/12/11

まつもと ゆきひろです

[#32539] Re: [ruby-cvs:21409] Ruby:r14172 (trunk): * transcode.c: new file to provide encoding conversion features. — Nobuyoshi Nakada <nobu@...> 2007/12/11

なかだです。

[#32550] Binary String — Hidetoshi NAGAI <nagai@...>

永井@知能.九工大です.

204 messages 2007/12/12
[#32551] Re: Binary String — Yukihiro Matsumoto <matz@...> 2007/12/12

まつもと ゆきひろです

[#32552] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2007/12/12

永井@知能.九工大です.

[#32553] Re: Binary String — Yukihiro Matsumoto <matz@...> 2007/12/12

まつもと ゆきひろです

[#32560] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2007/12/12

永井@知能.九工大です.

[#32561] Re: Binary String — Nobuyoshi Nakada <nobu@...> 2007/12/12

なかだです。

[#33018] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/11

永井@知能.九工大です.

[#33019] Re: Binary String — Tanaka Akira <akr@...> 2008/01/11

In article <20080111.171950.78716471.nagai@ai.kyutech.ac.jp>,

[#33024] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/11

永井@知能.九工大です.

[#33027] Re: Binary String — Tanaka Akira <akr@...> 2008/01/11

In article <20080111.184442.74744388.nagai@ai.kyutech.ac.jp>,

[#33041] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/11

永井@知能.九工大です.

[#33047] Re: Binary String — Tanaka Akira <akr@...> 2008/01/11

In article <20080112.004750.74741782.nagai@ai.kyutech.ac.jp>,

[#33055] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/12

永井@知能.九工大です.

[#33080] Re: Binary String — Tanaka Akira <akr@...> 2008/01/13

In article <20080112.100830.112615025.nagai@ai.kyutech.ac.jp>,

[#33104] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/14

永井@知能.九工大です.

[#33108] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/15

成瀬です。

[#33121] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/15

永井@知能.九工大です.

[#33123] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/15

成瀬です。

[#33127] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/16

永井@知能.九工大です.

[#33138] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/16

成瀬です。

[#33147] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/17

永井@知能.九工大です.

[#33152] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/17

成瀬です。

[#33153] Re: Binary String — 遊楽庵 <yu_raku_an@...> 2008/01/17

遊楽庵です。

[#33154] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/17

成瀬です。

[#33157] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/17

まつもと ゆきひろです

[#33330] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/23

成瀬です。

[#33336] Re: Binary String — Tanaka Akira <akr@...> 2008/01/23

In article <47975933.8010907@airemix.com>,

[#33337] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/23

まつもと ゆきひろです

[#33346] Re: Binary String — "U.Nakamura" <usa@...> 2008/01/24

こんにちは、なかむら(う)です。

[#33348] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/24

まつもと ゆきひろです

[#33352] Re: Binary String — "U.Nakamura" <usa@...> 2008/01/24

こんにちは、なかむら(う)です。

[#33353] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/24

まつもと ゆきひろです

[#33122] Re: Binary String — Tanaka Akira <akr@...> 2008/01/15

In article <20080115.024201.41653719.nagai@ai.kyutech.ac.jp>,

[#33126] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/16

永井@知能.九工大です.

[#33151] Re: Binary String — Tanaka Akira <akr@...> 2008/01/17

In article <20080116.102057.41656941.nagai@ai.kyutech.ac.jp>,

[#33160] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/17

永井@知能.九工大です.

[#33165] Re: Binary String — Tanaka Akira <akr@...> 2008/01/18

In article <20080117.233832.74721189.nagai@ai.kyutech.ac.jp>,

[#33188] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/19

永井@知能.九工大です.

[#33193] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/19

まつもと ゆきひろです

[#33202] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/19

永井@知能.九工大です.

[#33230] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/20

まつもと ゆきひろです

[#33236] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/21

永井@知能.九工大です.

[#33238] Re: Binary String — SASADA Koichi <ko1@...> 2008/01/21

 m17n には近づかないようにしているささだです。

[#33241] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/21

成瀬です。

[#33248] Re: Binary String — Yukihiro Matsumoto <matz@...> 2008/01/21

まつもと ゆきひろです

[#33281] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/22

永井@知能.九工大です.

[#33285] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/22

成瀬です。

[#33318] Re: Binary String — Hidetoshi NAGAI <nagai@...> 2008/01/23

永井@知能.九工大です.

[#33186] Ruby1.9 String バイト列へのインデックス アクセス — "Hisanori Kiryu" <hkiryu@...> 2008/01/19

長文失礼します。

[#33192] Re: Ruby1.9 String バイト列へのインデックス アクセス — Yukihiro Matsumoto <matz@...> 2008/01/19

まつもと ゆきひろです

[#33195] Re: Ruby1.9 String バイト列へのインデックス アクセス — rubikitch@... 2008/01/19

From: Yukihiro Matsumoto <matz@ruby-lang.org>

[#33199] Re: Ruby1.9 String バイト列へのインデックス アクセス — "NARUSE, Yui" <naruse@...> 2008/01/19

成瀬です。

[#33020] Re: Binary String — "NARUSE, Yui" <naruse@...> 2008/01/11

成瀬です。

[#32610] 1.9.1 issues left (as of 12/15) — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

14 messages 2007/12/15

[#32715] issues left as of 12/25 2:00am JST — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

41 messages 2007/12/24
[#32738] issues left as of 12/25 noon JST — Yukihiro Matsumoto <matz@...> 2007/12/25

まつもと ゆきひろです

[#32739] Re: issues left as of 12/25 noon JST — Yukihiro Matsumoto <matz@...> 2007/12/25

まつもと ゆきひろです

[#32791] Re: [ruby-list:44387] [ANN] Ruby 1.9.0 is released — SASADA Koichi <ko1@...>

 ささだです。

21 messages 2007/12/25

[#32823] class TimeSpan — "NARUSE, Yui" <naruse@...>

成瀬です。

18 messages 2007/12/27

[#32843] Windowでのデフォルトエンコーディング — KIMURA Koichi <kimura.koichi@...>

木村です。

30 messages 2007/12/28
[#32845] Re: Windowでのデフォルトエンコーディング — "U.Nakamura" <usa@...> 2007/12/28

こんにちは、なかむら(う)です。

[#32851] Re: Window でのデフォルトエンコーディング — Martin Duerst <duerst@...> 2007/12/28

At 13:55 07/12/28, U.Nakamura wrote:

[#32853] Re: Windowでのデフォルトエンコーディング — "NARUSE, Yui" <naruse@...> 2007/12/28

U.Nakamura wrote:

[#32857] Re: Windowでのデフォルトエンコーディング — "U.Nakamura" <usa@...> 2007/12/28

こんにちは、なかむら(う)です。

[#32852] Resolv::DNS#getaddresses doesn't return IPv6 address — "NARUSE, Yui" <naruse@...>

成瀬です。

17 messages 2007/12/28
[#32923] Re: Resolv::DNS#getaddresses doesn't return IPv6 address — Takahiro Kambe <taca@...> 2008/01/05

こんにちは。

[#32924] Re: Resolv::DNS#getaddresses doesn't return IPv6 address — "NARUSE, Yui" <naruse@...> 2008/01/05

成瀬です。

[#32925] Re: Resolv::DNS#getaddresses doesn't return IPv6 address — Takahiro Kambe <taca@...> 2008/01/05

In message <477EF0C9.4060103@airemix.com>

[#32929] Re: Resolv::DNS#getaddresses doesn't return IPv6 address — "NARUSE, Yui" <naruse@...> 2008/01/05

成瀬です

[ruby-dev:32493] Regexp#names, MatchData#names, MatchData#regexp

From: Tanaka Akira <akr@...>
Date: 2007-12-09 08:20:10 UTC
List: ruby-dev #32493
named capture まわりをそろえていて、やはり名前のリストを得る
メソッドが必要だろうということで、Regexp#names と
MatchData#names を実装してみましたが、どうでしょうか。

あと、match.names は match.regexp.names と同じ、とドキュメン
トに書こうとしたのですが MatchData#regexp がなかったのでこれ
もつけました。

Index: re.c
===================================================================
--- re.c	(revision 14159)
+++ re.c	(working copy)
@@ -513,6 +513,38 @@ rb_reg_options_m(VALUE re)
     return INT2NUM(options);
 }
 
+static int
+reg_names_iter(const OnigUChar *name, const OnigUChar *name_end,
+          int back_num, int *back_refs, OnigRegex regex, void *arg)
+{
+    VALUE ary = (VALUE)arg;
+    rb_ary_push(ary, rb_str_new((const char *)name, name_end-name));
+    return 0;
+}
+
+/*
+ * call-seq:
+ *    rxp.names   => [name1, name2, ...]
+ *
+ * Returns an array of names of named captures.
+ *
+ *     /(?<foo>.)(?<bar>.)(?<baz>.)/.names
+ *     #=> ["foo", "bar", "baz"]
+ *
+ *     /(?<foo>.)(?<foo>.)/.names
+ *     #=> ["foo"]
+ *
+ *     /(.)(.)/.names' 
+ *     #=> []
+ */
+
+static VALUE
+rb_reg_names(VALUE re)
+{
+    VALUE ary = rb_ary_new();
+    onig_foreach_name(RREGEXP(re)->ptr, reg_names_iter, (void*)ary);
+    return ary;
+}
 
 static Regexp*
 make_regexp(const char *s, long len, rb_encoding *enc, int flags, onig_errmsg_buffer err)
@@ -595,6 +627,42 @@ match_init_copy(VALUE obj, VALUE orig)
 
 
 /*
+ * call-seq:
+ *    mtch.regexp   => regexp
+ *
+ * Returns the regexp.
+ *
+ *     m = /a.*b/.match("abc")
+ *     m.regexp #=> /a.*b/
+ */
+
+static VALUE
+match_regexp(VALUE match)
+{
+    return RMATCH(match)->regexp;
+}
+
+/*
+ * call-seq:
+ *    mtch.names   => [name1, name2, ...]
+ *
+ * Returns an array of names of named captures.
+ * It is same as mtch.regexp.names.
+ *
+ *     /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
+ *     #=> ["foo", "bar", "baz"]
+ *
+ *     m = /(?<x>.)(?<y>.)?/.match("a") #=> #<MatchData "a" x:"a" y:nil>
+ *     m.names                          #=> ["x", "y"]
+ */
+
+static VALUE
+match_names(VALUE match)
+{
+    return rb_reg_names(RMATCH(match)->regexp);
+}
+
+/*
  *  call-seq:
  *     mtch.length   => integer
  *     mtch.size     => integer
@@ -2754,6 +2822,7 @@ Init_Regexp(void)
     rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
     rb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0); /* in encoding.c */
     rb_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0);
+    rb_define_method(rb_cRegexp, "names", rb_reg_names, 0);
 
     rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE));
     rb_define_const(rb_cRegexp, "EXTENDED", INT2FIX(ONIG_OPTION_EXTEND));
@@ -2766,6 +2835,8 @@ Init_Regexp(void)
     rb_undef_method(CLASS_OF(rb_cMatch), "new");
 
     rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
+    rb_define_method(rb_cMatch, "regexp", match_regexp, 0);
+    rb_define_method(rb_cMatch, "names", match_names, 0);
     rb_define_method(rb_cMatch, "size", match_size, 0);
     rb_define_method(rb_cMatch, "length", match_size, 0);
     rb_define_method(rb_cMatch, "offset", match_offset, 1);
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread

Prev Next