[macruby-changes] [3808] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 18 14:48:31 PDT 2010
Revision: 3808
http://trac.macosforge.org/projects/ruby/changeset/3808
Author: lsansonetti at apple.com
Date: 2010-03-18 14:48:28 -0700 (Thu, 18 Mar 2010)
Log Message:
-----------
added support for regexps marshal'ing
Modified Paths:
--------------
MacRuby/trunk/marshal.c
MacRuby/trunk/re.cpp
MacRuby/trunk/re.h
Modified: MacRuby/trunk/marshal.c
===================================================================
--- MacRuby/trunk/marshal.c 2010-03-18 20:48:58 UTC (rev 3807)
+++ MacRuby/trunk/marshal.c 2010-03-18 21:48:28 UTC (rev 3808)
@@ -16,6 +16,7 @@
#include "ruby/encoding.h"
#include "encoding.h"
#include "id.h"
+#include "re.h"
#include <math.h>
#ifdef HAVE_FLOAT_H
@@ -786,9 +787,9 @@
case T_REGEXP:
w_uclass(obj, rb_cRegexp, arg);
w_byte(TYPE_REGEXP, arg);
- // TODO
- //w_bytes(RREGEXP(obj)->str, RREGEXP(obj)->len, arg);
- //w_byte((char)rb_reg_options(obj), arg);
+ VALUE re_str = rb_regexp_source(obj);
+ w_bytes(RSTRING_PTR(re_str), RSTRING_LEN(re_str), arg);
+ w_byte(rb_reg_options_to_mri(rb_reg_options(obj)), arg);
break;
case T_ARRAY:
@@ -1499,7 +1500,7 @@
{
volatile VALUE str = r_bytes(arg);
const char *cstr = RSTRING_PTR(str);
- const int options = r_byte(arg);
+ const int options = rb_reg_options_from_mri(r_byte(arg));
v = r_entry(rb_reg_new(cstr, strlen(cstr), options), arg);
v = r_leave(v, arg);
}
Modified: MacRuby/trunk/re.cpp
===================================================================
--- MacRuby/trunk/re.cpp 2010-03-18 20:48:58 UTC (rev 3807)
+++ MacRuby/trunk/re.cpp 2010-03-18 21:48:28 UTC (rev 3808)
@@ -789,17 +789,22 @@
*
*/
-static VALUE
-regexp_source(VALUE rcv, SEL sel)
+VALUE
+rb_regexp_source(VALUE re)
{
- assert(RREGEXP(rcv)->unistr != NULL);
+ assert(RREGEXP(re)->unistr != NULL);
- const UChar *chars = RREGEXP(rcv)->unistr->getBuffer();
- const int32_t chars_len = RREGEXP(rcv)->unistr->length();
+ const UChar *chars = RREGEXP(re)->unistr->getBuffer();
+ const int32_t chars_len = RREGEXP(re)->unistr->length();
assert(chars_len >= 0);
- VALUE str = rb_unicode_str_new(chars, chars_len);
+ return rb_unicode_str_new(chars, chars_len);
+}
+static VALUE
+regexp_source(VALUE rcv, SEL sel)
+{
+ VALUE str = rb_regexp_source(rcv);
if (OBJ_TAINTED(rcv)) {
OBJ_TAINT(str);
}
@@ -1824,4 +1829,36 @@
FL_SET(match, MATCH_BUSY);
}
+int
+rb_reg_options_from_mri(int mri_opt)
+{
+ int opt = 0;
+ if (mri_opt & 1) {
+ opt |= REGEXP_OPT_IGNORECASE;
+ }
+ if (mri_opt & 2) {
+ opt |= REGEXP_OPT_EXTENDED;
+ }
+ if (mri_opt & 4) {
+ opt |= REGEXP_OPT_MULTILINE;
+ }
+ return opt;
+}
+
+int
+rb_reg_options_to_mri(int opt)
+{
+ int mri_opt = 0;
+ if (opt & REGEXP_OPT_IGNORECASE) {
+ mri_opt |= 1;
+ }
+ if (opt & REGEXP_OPT_EXTENDED) {
+ mri_opt |= 2;
+ }
+ if (opt & REGEXP_OPT_MULTILINE) {
+ mri_opt |= 4;
+ }
+ return mri_opt;
+}
+
} // extern "C"
Modified: MacRuby/trunk/re.h
===================================================================
--- MacRuby/trunk/re.h 2010-03-18 20:48:58 UTC (rev 3807)
+++ MacRuby/trunk/re.h 2010-03-18 21:48:28 UTC (rev 3808)
@@ -22,7 +22,11 @@
VALUE rb_reg_quote(VALUE pat);
VALUE rb_reg_regcomp(VALUE str);
int rb_reg_search(VALUE re, VALUE str, int pos, bool reverse);
+VALUE rb_regexp_source(VALUE re);
+int rb_reg_options_to_mri(int opt);
+int rb_reg_options_from_mri(int mri_opt);
+
void regexp_get_uchars(VALUE re, const UChar **chars_p, long *chars_len_p);
typedef struct rb_match_result {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100318/50eb3116/attachment-0001.html>
More information about the macruby-changes
mailing list