diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-18 08:04:57 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-18 08:04:57 +0000 |
commit | 3b0f857958ab5a04c245b6fb9f2f0b69b6b4eb48 (patch) | |
tree | 430116f9233470f43c32dd3724b44cebec2f8821 /re.c | |
parent | 9ad8f86ceba98858e0f7c5e74d54b79fa7cfadb3 (diff) | |
download | ruby-3b0f857958ab5a04c245b6fb9f2f0b69b6b4eb48.tar.gz ruby-3b0f857958ab5a04c245b6fb9f2f0b69b6b4eb48.tar.xz ruby-3b0f857958ab5a04c245b6fb9f2f0b69b6b4eb48.zip |
* re.c (rb_reg_to_s): new function for Regexp#to_s.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 43 |
1 files changed, 42 insertions, 1 deletions
@@ -349,6 +349,47 @@ rb_reg_inspect(re) return rb_reg_desc(RREGEXP(re)->str, RREGEXP(re)->len, re); } +static VALUE +rb_reg_to_s(re) + VALUE re; +{ + int all; + VALUE str = rb_str_buf_new2("(?"); + + rb_reg_check(re); + + all = 1; + if (RREGEXP(re)->ptr->options & RE_OPTION_MULTILINE) + rb_str_buf_cat2(str, "m"); + else + all = 0; + if (RREGEXP(re)->ptr->options & RE_OPTION_IGNORECASE) + rb_str_buf_cat2(str, "i"); + else + all = 0; + if (RREGEXP(re)->ptr->options & RE_OPTION_EXTENDED) + rb_str_buf_cat2(str, "x"); + else + all = 0; + + if (!all) { + rb_str_buf_cat2(str, "-"); + if (!(RREGEXP(re)->ptr->options & RE_OPTION_MULTILINE)) + rb_str_buf_cat2(str, "m"); + if (!(RREGEXP(re)->ptr->options & RE_OPTION_IGNORECASE)) + rb_str_buf_cat2(str, "i"); + if (!(RREGEXP(re)->ptr->options & RE_OPTION_EXTENDED)) + rb_str_buf_cat2(str, "x"); + } + + rb_str_buf_cat2(str, ":"); + rb_reg_expr_str(str, RREGEXP(re)->str, RREGEXP(re)->len); + rb_str_buf_cat2(str, ")"); + + OBJ_INFECT(str, re); + return str; +} + static void rb_reg_raise(s, len, err, re) const char *s; @@ -1455,7 +1496,7 @@ Init_Regexp() rb_define_method(rb_cRegexp, "===", rb_reg_match, 1); rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0); rb_define_method(rb_cRegexp, "match", rb_reg_match_m, 1); - rb_define_method(rb_cRegexp, "to_s", rb_reg_inspect, 0); + rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0); rb_define_method(rb_cRegexp, "inspect", rb_reg_inspect, 0); rb_define_method(rb_cRegexp, "source", rb_reg_source, 0); rb_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0); |