----Next_Part(Wed_Nov_28_21:04:14_2001_535)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

酒井です。

またちょっとしたパッチを作ってみました。

- wstring-wctrans.diff
    WString#transformという名前でtowctransのラッパーを作ってみました。
    "tolower"と"toupper"以外のマッピング名は実装依存なのですが、
    例えば、glibc2.2ならば
    WString.new('おはよう').transform('tojkata') #L"オハヨウ"
    というような事も茲泙后

齡鱸鈑竅黼竝隰粡聿
    徨鱸鈑c癈繝蹐造亮汰。
    最託笂蜒蹐造wcscasecmpが使える場合はらを使おうかと思ったのですが、
    これくらいなら自前で持った方が良いかなという気がして来たので、
    have_funcによるチェックはコメントアウトしてあります。

-- さかい

----Next_Part(Wed_Nov_28_21:04:14_2001_535)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wstring-wctrans.diff"

diff -u wstring-0.0.2.orig/wstring/wstring.cpp wstring-0.0.2/wstring/wstring.cpp
--- wstring-0.0.2.orig/wstring/wstring.cpp	Thu Nov 22 02:13:50 2001
+++ wstring-0.0.2/wstring/wstring.cpp	Thu Nov 22 20:41:09 2001
@@ -380,6 +380,48 @@
     return rb_wstring;
 }
 
+class WCTrans{
+private:
+    wctrans_t desc;
+public:
+    typedef wchar_t result_type;
+    WCTrans(wctrans_t desc){
+        this->desc  esc;
+    }
+    result_type operator()(result_type src){
+        return towctrans(src, desc);
+    }
+};
+
+class mapping_not_found{};
+
+VALUE ws_transform(VALUE self_, VALUE property_)
+{
+    std::wstring* self  et_wstring(self_);
+    const char* property  TR2CSTR(property_);
+
+    try {
+        utility::scoped_locale l(LC_CTYPE, get_wstring_locale(self_));
+        wctrans_t desc  ctrans(property);
+        if (desc 0)
+            throw mapping_not_found();
+
+        WCTrans op(desc);
+        bool modified  alse;
+        detail::transform(self->begin(), self->end(), self->begin(), op, modified);
+        return modified ? self_ : Qnil;
+    } catch(mapping_not_found&) {
+        rb_raise(WStringError, "mapping \"%s\" not found", property);
+    }
+}
+
+VALUE ws_transform_copy(VALUE self, VALUE property)
+{
+    VALUE rb_wstring  s_dup(self);
+    ws_transform(rb_wstring, property);
+    return rb_wstring;
+}
+
 VALUE ws_dup(VALUE self_)
 {
     VALUE klass  LASS_OF(self_);
@@ -1374,11 +1416,13 @@
     rb_define_method(WString, "downcase", WS_CAST_FUNC(ws_downcase_copy), 0);
     rb_define_method(WString, "swapcase", WS_CAST_FUNC(ws_swapcase_copy), 0);
     rb_define_method(WString, "capitalize", WS_CAST_FUNC(ws_capitalize_copy), 0);
+    rb_define_method(WString, "transform", WS_CAST_FUNC(ws_transform_copy), 1);
     
     rb_define_method(WString, "upcase!", WS_CAST_FUNC(ws_upcase), 0);
     rb_define_method(WString, "downcase!", WS_CAST_FUNC(ws_downcase), 0);
     rb_define_method(WString, "swapcase!", WS_CAST_FUNC(ws_swapcase), 0);
     rb_define_method(WString, "capitalize!", WS_CAST_FUNC(ws_capitalize), 0);
+    rb_define_method(WString, "transform!", WS_CAST_FUNC(ws_transform), 1);
     
     rb_define_method(WString, "hex", WS_CAST_FUNC(ws_hex), 0);
     rb_define_method(WString, "oct", WS_CAST_FUNC(ws_oct), 0);

----Next_Part(Wed_Nov_28_21:04:14_2001_535)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wstring-casecmp.diff"

diff -u wstring-0.0.2.orig/wstring/extconf.rb wstring-0.0.2/wstring/extconf.rb
--- wstring-0.0.2.orig/wstring/extconf.rb	Thu Nov 22 02:13:50 2001
+++ wstring-0.0.2/wstring/extconf.rb	Thu Nov 22 14:51:56 2001
@@ -25,6 +25,11 @@
   have_library('stdc++', nil)
 end
 
+#unless have_func('wcsicmp')
+#  $CFLAGS +  -D_GNU_SOURCE'
+#  have_func('wcscasecmp')
+#end
+
 if (RUBY_PLATFORM /mswin/)
   # if optimizations are enabled, Visual C++ deletes volatile.
   # it causes problems with GC so we lazily disable optimizations.
diff -u wstring-0.0.2.orig/wstring/wstring.cpp wstring-0.0.2/wstring/wstring.cpp
--- wstring-0.0.2.orig/wstring/wstring.cpp	Thu Nov 22 02:13:50 2001
+++ wstring-0.0.2/wstring/wstring.cpp	Thu Nov 22 15:01:06 2001
@@ -406,6 +406,29 @@
     //return INT2FIX(wcscoll(get_wstring(self)->c_str(), get_wstring(other)->c_str()));
 }
 
+VALUE ws_casecmp(VALUE self, VALUE other)
+{
+    utility::must_be_wstring(other);
+    utility::same_locale(get_wstring_locale(self), get_wstring_locale(other));
+    utility::scoped_locale l(LC_CTYPE, get_wstring_locale(self));
+#if defined(HAVE_WCSICMP)
+    return INT2FIX(wcsicmp(get_wstring(self)->c_str(), get_wstring(other)->c_str()));
+#elif defined(HAVE_WCSCASECMP)
+    return INT2FIX(wcscasecmp(get_wstring(self)->c_str(), get_wstring(other)->c_str()));
+#else
+    wstring* ws1  et_wstring(self);
+    wstring* ws2  et_wstring(other);
+    for (size_t i  ; i < min(ws1->size(), ws2->size()); i++) {
+        wint_t c1, c2;
+        c1  owlower((*ws1)[i]);
+        c2  owlower((*ws2)[i]);
+        if (c1 ! 2)
+            return INT2FIX(c1 - c2);
+    }
+    return INT2FIX(ws1->size() - ws2->size());
+#endif
+}
+
 VALUE ws_plus(VALUE self, VALUE other)
 {
     utility::must_be_wstring(other);
@@ -1341,6 +1364,7 @@
     rb_define_method(WString, "clone", WS_CAST_FUNC(ws_dup), 0);
     rb_define_method(WString, "dup", WS_CAST_FUNC(ws_dup), 0);
     rb_define_method(WString, "<, WS_CAST_FUNC(ws_cmp), 1);
+    rb_define_method(WString, "casecmp", WS_CAST_FUNC(ws_casecmp), 1);
     rb_define_method(WString, ", WS_CAST_FUNC(ws_equal), 1);
     rb_define_method(WString, "", WS_CAST_FUNC(ws_equal), 1);
     rb_define_method(WString, "eql?", WS_CAST_FUNC(ws_equal), 1);

----Next_Part(Wed_Nov_28_21:04:14_2001_535)----