Revision
3638
Author
lsansonetti@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

Diff

Modified: MacRuby/branches/icu/re.cpp (3637 => 3638)


--- 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);