[macruby-changes] [3583] MacRuby/branches/icu
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 19 22:42:42 PST 2010
Revision: 3583
http://trac.macosforge.org/projects/ruby/changeset/3583
Author: lsansonetti at apple.com
Date: 2010-02-19 22:42:42 -0800 (Fri, 19 Feb 2010)
Log Message:
-----------
more string/regexp work
Modified Paths:
--------------
MacRuby/branches/icu/dispatcher.cpp
MacRuby/branches/icu/re.cpp
MacRuby/branches/icu/re.h
MacRuby/branches/icu/string.c
Modified: MacRuby/branches/icu/dispatcher.cpp
===================================================================
--- MacRuby/branches/icu/dispatcher.cpp 2010-02-20 04:27:42 UTC (rev 3582)
+++ MacRuby/branches/icu/dispatcher.cpp 2010-02-20 06:42:42 UTC (rev 3583)
@@ -16,6 +16,7 @@
#include "dtrace.h"
#include "array.h"
#include "hash.h"
+#include "encoding.h"
#include "re.h"
#include <execinfo.h>
Modified: MacRuby/branches/icu/re.cpp
===================================================================
--- MacRuby/branches/icu/re.cpp 2010-02-20 04:27:42 UTC (rev 3582)
+++ MacRuby/branches/icu/re.cpp 2010-02-20 06:42:42 UTC (rev 3583)
@@ -12,6 +12,7 @@
#include "ruby/ruby.h"
#include "encoding.h"
#include "objc.h"
+#include "re.h"
extern "C" {
@@ -368,15 +369,11 @@
}
}
-static int
-rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, bool reverse)
-{
- return reverse ? -pos : rb_str_chars_len(str) - pos;
-}
-
-static int
+int
rb_reg_search(VALUE re, VALUE str, int pos, bool reverse)
{
+ assert(!reverse); // TODO
+
const long len = rb_str_chars_len(str);
if (pos > len || pos < 0) {
rb_backref_set(Qnil);
Modified: MacRuby/branches/icu/re.h
===================================================================
--- MacRuby/branches/icu/re.h 2010-02-20 04:27:42 UTC (rev 3582)
+++ MacRuby/branches/icu/re.h 2010-02-20 06:42:42 UTC (rev 3583)
@@ -15,7 +15,14 @@
bool rb_char_to_icu_option(int c, int *option);
VALUE regexp_eqq(VALUE rcv, SEL sel, VALUE str);
+int rb_reg_search(VALUE re, VALUE str, int pos, bool reverse);
+static inline int
+rb_reg_adjust_startpos(VALUE re, VALUE str, int pos, bool reverse)
+{
+ return reverse ? -pos : rb_str_chars_len(str) - pos;
+}
+
#if defined(__cplusplus)
} // extern "C"
#endif
Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c 2010-02-20 04:27:42 UTC (rev 3582)
+++ MacRuby/branches/icu/string.c 2010-02-20 06:42:42 UTC (rev 3583)
@@ -16,6 +16,7 @@
#include "ruby.h"
#include "ruby/encoding.h"
#include "encoding.h"
+#include "re.h"
#include "objc.h"
#include "id.h"
@@ -1312,13 +1313,20 @@
*/
static VALUE
+rb_str_subpat(VALUE str, VALUE re, int nth)
+{
+ if (rb_reg_search(re, str, 0, 0) >= 0) {
+ return rb_reg_nth_match(nth, rb_backref_get());
+ }
+ return Qnil;
+}
+
+static VALUE
rstr_aref(VALUE str, SEL sel, int argc, VALUE *argv)
{
if (argc == 2) {
if (TYPE(argv[0]) == T_REGEXP) {
- // TODO
- //return rb_str_subpat(str, argv[0], NUM2INT(argv[1]));
- return Qnil;
+ return rb_str_subpat(str, argv[0], NUM2INT(argv[1]));
}
return str_substr(str, NUM2LONG(argv[0]), NUM2LONG(argv[1]));
}
@@ -1337,7 +1345,7 @@
return str;
case T_REGEXP:
- abort(); // TODO
+ return rb_str_subpat(str, indx, 0);
case T_STRING:
{
@@ -1427,10 +1435,8 @@
switch (TYPE(sub)) {
case T_REGEXP:
- // TODO
- //pos = rb_reg_adjust_startpos(sub, str, pos, 0);
- //pos = rb_reg_search(sub, str, pos, 0);
- //pos = rb_str_sublen(str, pos);
+ pos = rb_reg_adjust_startpos(sub, self, pos, false);
+ pos = rb_reg_search(sub, self, pos, false);
break;
default:
@@ -1502,13 +1508,24 @@
rstr_concat(VALUE self, SEL sel, VALUE other)
{
rstr_modify(self);
+
+ long codepoint = 0;
switch (TYPE(other)) {
case T_FIXNUM:
- abort(); // TODO
+ codepoint = FIX2LONG(other);
+ break;
+ case T_BIGNUM:
+ codepoint = rb_big2ulong(other);
+ break;
+
default:
str_concat_string(RSTR(self), str_need_string(other));
+ return self;
}
+
+ // TODO: handle codepoint
+
return self;
}
@@ -2312,7 +2329,11 @@
VALUE
rb_str_subseq(VALUE str, long beg, long len)
{
- abort(); // TODO
+ if (IS_RSTR(str)) {
+ return str_substr(str, beg, len);
+ }
+ // TODO
+ return Qnil;
}
VALUE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100219/92bf168f/attachment.html>
More information about the macruby-changes
mailing list