[macruby-changes] [3638] MacRuby/branches/icu/re.cpp

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 26 16:52:42 PST 2010


Revision: 3638
          http://trac.macosforge.org/projects/ruby/changeset/3638
Author:   lsansonetti at apple.com
Date:     2010-02-26 16:52:41 -0800 (Fri, 26 Feb 2010)
Log Message:
-----------
ICU does not support the [[:word:]] class so we need to work around it

Modified Paths:
--------------
    MacRuby/branches/icu/re.cpp

Modified: MacRuby/branches/icu/re.cpp
===================================================================
--- MacRuby/branches/icu/re.cpp	2010-02-27 00:22:35 UTC (rev 3637)
+++ MacRuby/branches/icu/re.cpp	2010-02-27 00:52:41 UTC (rev 3638)
@@ -129,12 +129,29 @@
     return rb_unicode_str_new(&chars[beg], len);
 }
 
+static void
+sanitize_regexp_string(UnicodeString *unistr)
+{
+    // ICU does not support [[:word::], so we need to replace all
+    // occurences by \w.
+    UChar word_chars[10] = {'[', '[', ':', 'w', 'o', 'r', 'd', ':', ']', ']'};
+    UnicodeString word_str(word_chars, 10);
+    UChar repl_chars[2] = {'\\', 'w'};
+    UnicodeString repl_str(repl_chars, 2);
+    int32_t pos;
+    while ((pos = unistr->indexOf(word_str)) >= 0) {
+	unistr->replace(pos, 10, repl_str);
+    }
+}
+
 static bool
 init_from_string(rb_regexp_t *regexp, VALUE str, int option, VALUE *excp)
 {
     UnicodeString *unistr = str_to_unistr(str);
     assert(unistr != NULL);
 
+    sanitize_regexp_string(unistr);
+
     UParseError pe;
     UErrorCode status = U_ZERO_ERROR;
     RegexPattern *pattern = RegexPattern::compile(*unistr, option, pe, status);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100226/f28e7bb7/attachment.html>


More information about the macruby-changes mailing list