[macruby-changes] [3686] MacRuby/branches/icu/re.cpp
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 3 14:37:51 PST 2010
Revision: 3686
http://trac.macosforge.org/projects/ruby/changeset/3686
Author: lsansonetti at apple.com
Date: 2010-03-03 14:37:48 -0800 (Wed, 03 Mar 2010)
Log Message:
-----------
fixed #to_s and #inspect to now display regexp flags
Modified Paths:
--------------
MacRuby/branches/icu/re.cpp
Modified: MacRuby/branches/icu/re.cpp
===================================================================
--- MacRuby/branches/icu/re.cpp 2010-03-03 22:16:51 UTC (rev 3685)
+++ MacRuby/branches/icu/re.cpp 2010-03-03 22:37:48 UTC (rev 3686)
@@ -269,8 +269,6 @@
return rb_reg_quote(reg_operand(pat, true));
}
-
-
/*
* call-seq:
* Regexp.union(pat1, pat2, ...) => new_regexp
@@ -808,7 +806,22 @@
VALUE str = rb_str_new2("/");
rb_str_concat(str, regexp_source(rcv, 0));
rb_str_cat2(str, "/");
- // TODO: add options there.
+
+ const uint32_t options = rb_reg_options(rcv);
+ const bool mode_m = options & REGEXP_OPT_MULTILINE;
+ const bool mode_i = options & REGEXP_OPT_IGNORECASE;
+ const bool mode_x = options & REGEXP_OPT_EXTENDED;
+
+ if (mode_m) {
+ rb_str_cat2(str, "m");
+ }
+ if (mode_i) {
+ rb_str_cat2(str, "i");
+ }
+ if (mode_x) {
+ rb_str_cat2(str, "x");
+ }
+
return str;
}
@@ -835,10 +848,40 @@
static VALUE
regexp_to_s(VALUE rcv, SEL sel)
{
- VALUE str = rb_str_new2("(?:");
- // TODO: add options there.
+ VALUE str = rb_str_new2("(?");
+
+ const uint32_t options = rb_reg_options(rcv);
+ const bool mode_m = options & REGEXP_OPT_MULTILINE;
+ const bool mode_i = options & REGEXP_OPT_IGNORECASE;
+ const bool mode_x = options & REGEXP_OPT_EXTENDED;
+
+ if (mode_m) {
+ rb_str_cat2(str, "m");
+ }
+ if (mode_i) {
+ rb_str_cat2(str, "i");
+ }
+ if (mode_x) {
+ rb_str_cat2(str, "x");
+ }
+
+ if (!mode_m || !mode_i || !mode_x) {
+ rb_str_cat2(str, "-");
+ if (!mode_m) {
+ rb_str_cat2(str, "m");
+ }
+ if (!mode_i) {
+ rb_str_cat2(str, "i");
+ }
+ if (!mode_x) {
+ rb_str_cat2(str, "x");
+ }
+ }
+
+ rb_str_cat2(str, ":");
rb_str_concat(str, regexp_source(rcv, 0));
rb_str_cat2(str, ")");
+
return str;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100303/e8a9568a/attachment.html>
More information about the macruby-changes
mailing list