----Next_Part(Wed_Nov_14_23:51:23_2001_708)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

酒井です。

locale周りはあれからいじっていませんが、
いくつか手元にあった小さなパッチを送ります。
もし良かったら取りこんでやって下さい。

wstring-sysfail.diff
  変換に失敗した場合にはerrnoにエラーコードが入っているはずなので、
  独自の例外を発生させるよりrb_sys_failを呼ぶ方がrubyっぽいかも。

wstring-wcswidth.diff
  文字列の幅を取得するwcswidthという関数へのインターフェースです。
  XPG5では定義されていますが、ISO Cでは定義されていないので、
  あんましポータブルじゃありませんが…

wstring-makestring.diff
  -
 
-- さかい

----Next_Part(Wed_Nov_14_23:51:23_2001_708)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wstring-sysfail.diff"

--- wstring-0.0.1/wstring/detail.cpp~	Thu Oct 25 00:19:16 2001
+++ wstring-0.0.1/wstring/detail.cpp	Wed Nov 14 23:31:26 2001
@@ -23,7 +23,7 @@
 {
     const size_t wcs_size  bstowcs(0, mb_str, 0);
     if (wcs_size static_cast<size_t>(-1))
-        rb_raise(WStringError, "failed to convert argument to wide string");
+        rb_sys_fail("failed to convert argument to wide string");
     return wcs_size;
 }
 
@@ -32,7 +32,7 @@
 {
     const size_t ret  bstowcs(wc_str, mb_str, wcs_size);
     if (ret static_cast<size_t>(-1))
-        rb_raise(WStringError, "failed to convert argument to wide string");
+        rb_sys_fail("failed to convert argument to wide string");
     assert(ret wcs_size);
     return ret;
 }
@@ -42,7 +42,7 @@
 {
     const size_t mbs_size  cstombs(0, wc_str, 0);
     if (mbs_size static_cast<size_t>(-1))
-        rb_raise(WStringError, "failed to convert argument to multi-byte string");
+        rb_sys_fail("failed to convert argument to multi-byte string");
     return mbs_size;
 }
 
@@ -51,7 +51,7 @@
 {
     const size_t ret  cstombs(mb_str, wc_str, mbs_size);
     if (ret static_cast<size_t>(-1))
-        rb_raise(WStringError, "failed to convert argument to multi-byte string");
+        rb_sys_fail("failed to convert argument to multi-byte string");
     assert(ret mbs_size);
     return ret;
 }
@@ -91,7 +91,7 @@
         const size_t ret  bsrtowcs(buf, &mb_str, buf_size, &state);
         if (ret static_cast<size_t>(-1)) {
             delete wstring;
-            rb_raise(WStringError, "failed to convert argument to wide string");
+            rb_sys_fail("failed to convert argument to wide string");
         } else {
             wstring->append(buf, buf + ret);
         }

----Next_Part(Wed_Nov_14_23:51:23_2001_708)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wstring-wcswidth.diff"

diff -u wstring-0.0.1.orig/wstring/extconf.rb wstring-0.0.1/wstring/extconf.rb
--- wstring-0.0.1.orig/wstring/extconf.rb	Thu Oct 25 00:19:16 2001
+++ wstring-0.0.1/wstring/extconf.rb	Wed Nov 14 21:44:49 2001
@@ -1,5 +1,9 @@
 require 'mkmf'
 
+# wcswidth is defined by XPG5.
+$CFLAGS +  -D_XOPEN_SOURCEP0' # for glibc
+have_func('wcswidth', 'wchar.h')
+
 case RUBY_PLATFORM
 when /mswin/
   #mswin with STLport
diff -u wstring-0.0.1.orig/wstring/wstring.cpp wstring-0.0.1/wstring/wstring.cpp
--- wstring-0.0.1.orig/wstring/wstring.cpp	Thu Oct 25 00:19:16 2001
+++ wstring-0.0.1/wstring/wstring.cpp	Wed Nov 14 21:41:25 2001
@@ -734,6 +734,19 @@
     return rb_funcall(ws_to_s(self), rb_intern("intern"), 0);
 }
 
+#ifdef HAVE_WCSWIDTH
+
+VALUE ws_width(int argc, VALUE* argv, VALUE self_)
+{
+    std::wstring* self  et_wstring(self_);
+    VALUE len_;
+    rb_scan_args(argc, argv, "01", &len_);
+    // utility::SetLocale l(LC_CTYPE, get_wstring_locale(self_));
+    return INT2NUM(wcswidth(self->c_str(), argc 0 ? self->size() : NUM2INT(len_)));
+}
+
+#endif // HAVE_WCSWIDTH
+
 VALUE ws_center(VALUE self_, VALUE width_)
 {
     const int width  UM2INT(width_);
@@ -1336,6 +1349,9 @@
     
     rb_define_method(WString, "include?", WS_CAST_FUNC(ws_include), 1);
     
+#ifdef HAVE_WCSWIDTH    
+    rb_define_method(WString, "width", WS_CAST_FUNC(ws_width), -1);
+#endif
     rb_define_method(WString, "ljust", WS_CAST_FUNC(ws_ljust), 1);
     rb_define_method(WString, "rjust", WS_CAST_FUNC(ws_rjust), 1);
     rb_define_method(WString, "center", WS_CAST_FUNC(ws_center), 1);

----Next_Part(Wed_Nov_14_23:51:23_2001_708)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="wstring-makestring.diff"

--- wstring-0.0.1.orig/wstring/wstring.cpp      Thu Oct 25 00:19:16 2001
+++ wstring-0.0.1/wstring/wstring.cpp   Wed Nov 14 17:20:05 2001
@@ -73,10 +73,7 @@
 VALUE make_wstring(const wchar_t wc)
 {
     VALUE rb_wstring  ake_wstring();
-    wchar_t wc_str[2];
-    wc_str[0]  c;
-    wc_str[1]  '\0';
-    set_wstring(rb_wstring, new std::wstring(wc_str));
+    set_wstring(rb_wstring, new std::wstring(&wc, 1));
     return rb_wstring;
 }

----Next_Part(Wed_Nov_14_23:51:23_2001_708)----