[前][次][番号順一覧][スレッド一覧]

ruby-changes:3998

From: ko1@a...
Date: Fri, 15 Feb 2008 20:36:40 +0900 (JST)
Subject: [ruby-changes:3998] suke - Ruby:r15488 (trunk): * ext/win32ole/win32ole.c (ole_init_cp): initialize WIN32OLE.codepage

suke	2008-02-15 20:36:24 +0900 (Fri, 15 Feb 2008)

  New Revision: 15488

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/test/win32ole/test_win32ole.rb

  Log:
    * ext/win32ole/win32ole.c (ole_init_cp): initialize WIN32OLE.codepage
      according to Encoding.default_external.
    
    * test/win32ole/test_win32ole.rb: ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15488&r2=15487&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/win32ole/win32ole.c?r1=15488&r2=15487&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_win32ole.rb?r1=15488&r2=15487&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15487)
+++ ChangeLog	(revision 15488)
@@ -1,3 +1,10 @@
+Fri Feb 15 20:29:42 2008  Masaki Suketa  <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (ole_init_cp): initialize WIN32OLE.codepage
+	  according to Encoding.default_external.
+
+	* test/win32ole/test_win32ole.rb: ditto.
+
 Fri Feb 15 18:23:54 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_sub_bang, str_gsub): allows hash for replacement.
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 15487)
+++ ext/win32ole/win32ole.c	(revision 15488)
@@ -116,7 +116,7 @@
 
 #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
 
-#define WIN32OLE_VERSION "1.1.3"
+#define WIN32OLE_VERSION "1.1.4"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -259,6 +259,9 @@
 static void double2time(double v, int *y, int *m, int *d, int *hh, int *mm, int *ss);
 static double time_object2date(VALUE tmobj);
 static VALUE date2time_str(double date);
+static rb_encoding *ole_cp2encoding(UINT cp);
+static UINT ole_encoding2cp(rb_encoding *enc);
+static UINT ole_init_cp();
 static char *ole_wc2mb(LPWSTR pw);
 static VALUE ole_hresult2msg(HRESULT hr);
 static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
@@ -768,6 +771,86 @@
     return rb_str_new2(szTime);
 }
 
+#define ENC_MACHING_CP(enc,encname,cp) if(strcasecmp(rb_enc_name((enc)),(encname)) == 0) return cp
+
+static UINT ole_encoding2cp(rb_encoding *enc)
+{
+    /*
+     * Is there any better solution to convert 
+     * Ruby encoding to Windows codepage???
+     */
+    ENC_MACHING_CP(enc, "Big5", 950);
+    ENC_MACHING_CP(enc, "CP51932", 51932);
+    ENC_MACHING_CP(enc, "CP850", 850);
+    ENC_MACHING_CP(enc, "CP852", 852);
+    ENC_MACHING_CP(enc, "CP855", 855);
+    ENC_MACHING_CP(enc, "CP949", 949);
+    ENC_MACHING_CP(enc, "EUC-JP", 20932); 
+    ENC_MACHING_CP(enc, "EUC-KR", 51949);
+    ENC_MACHING_CP(enc, "EUC-TW", 51950);
+    ENC_MACHING_CP(enc, "GB18030", 54936);
+    ENC_MACHING_CP(enc, "GB2312", 51936);
+    ENC_MACHING_CP(enc, "GBK", 936);
+    ENC_MACHING_CP(enc, "IBM437", 437);
+    ENC_MACHING_CP(enc, "IBM737", 737);
+    ENC_MACHING_CP(enc, "IBM775", 775);
+    ENC_MACHING_CP(enc, "IBM852", 852);
+    ENC_MACHING_CP(enc, "IBM855", 855);
+    ENC_MACHING_CP(enc, "IBM857", 857);
+    ENC_MACHING_CP(enc, "IBM860", 860);
+    ENC_MACHING_CP(enc, "IBM861", 861);
+    ENC_MACHING_CP(enc, "IBM862", 862);
+    ENC_MACHING_CP(enc, "IBM863", 863);
+    ENC_MACHING_CP(enc, "IBM864", 864);
+    ENC_MACHING_CP(enc, "IBM865", 865);
+    ENC_MACHING_CP(enc, "IBM866", 866);
+    ENC_MACHING_CP(enc, "IBM869", 869);
+    ENC_MACHING_CP(enc, "ISO-2022-JP", 50220);
+    ENC_MACHING_CP(enc, "ISO-8859-1", 28591);
+    ENC_MACHING_CP(enc, "ISO-8859-15", 28605);
+    ENC_MACHING_CP(enc, "ISO-8859-2", 28592);
+    ENC_MACHING_CP(enc, "ISO-8859-3", 28593);
+    ENC_MACHING_CP(enc, "ISO-8859-4", 28594);
+    ENC_MACHING_CP(enc, "ISO-8859-5", 28595);
+    ENC_MACHING_CP(enc, "ISO-8859-6", 28596);
+    ENC_MACHING_CP(enc, "ISO-8859-7", 28597);
+    ENC_MACHING_CP(enc, "ISO-8859-8", 28598);
+    ENC_MACHING_CP(enc, "ISO-8859-9", 28599);
+    ENC_MACHING_CP(enc, "KOI8-R", 20866);
+    ENC_MACHING_CP(enc, "KOI8-U", 21866);
+    ENC_MACHING_CP(enc, "Shift_JIS", 932);
+    ENC_MACHING_CP(enc, "US-ASCII", 20127);
+    ENC_MACHING_CP(enc, "UTF-16BE", 1201);
+    ENC_MACHING_CP(enc, "UTF-16LE", 1200);
+    ENC_MACHING_CP(enc, "UTF-7", 65000);
+    ENC_MACHING_CP(enc, "UTF-8", 65001);
+    ENC_MACHING_CP(enc, "Windows-1250", 1250);
+    ENC_MACHING_CP(enc, "Windows-1251", 1251);
+    ENC_MACHING_CP(enc, "Windows-1252", 1252);
+    ENC_MACHING_CP(enc, "Windows-1253", 1253);
+    ENC_MACHING_CP(enc, "Windows-1254", 1254);
+    ENC_MACHING_CP(enc, "Windows-1255", 1255);
+    ENC_MACHING_CP(enc, "Windows-1256", 1256);
+    ENC_MACHING_CP(enc, "Windows-1257", 1257);
+    ENC_MACHING_CP(enc, "Windows-1258", 1258);
+    ENC_MACHING_CP(enc, "Windows-31J", 932);
+    ENC_MACHING_CP(enc, "Windows-874", 874);
+    ENC_MACHING_CP(enc, "eucJP-ms", 20932);
+    return CP_ACP;
+}
+
+static UINT
+ole_init_cp()
+{
+    UINT cp;
+    rb_encoding *encdef;
+    encdef = rb_default_external_encoding();
+    cp = ole_encoding2cp(encdef);
+    if (code_page_installed(cp)) {
+        cWIN32OLE_cp = cp;
+    }
+}
+
 struct myCPINFOEX {
   UINT MaxCharSize;
   BYTE DefaultChar[2];
@@ -8226,5 +8309,6 @@
 
     eWIN32OLERuntimeError = rb_define_class("WIN32OLERuntimeError", rb_eRuntimeError);
 
+    ole_init_cp();
     cWIN32OLE_enc = ole_cp2encoding(cWIN32OLE_cp);
 }
Index: test/win32ole/test_win32ole.rb
===================================================================
--- test/win32ole/test_win32ole.rb	(revision 15487)
+++ test/win32ole/test_win32ole.rb	(revision 15488)
@@ -263,9 +263,12 @@
                    guid)
     end
 
-    def test_s_codepage
-      assert_equal(WIN32OLE::CP_ACP, WIN32OLE.codepage)
-    end
+    # 
+    # WIN32OLE.codepage is initialized according to Encoding.default_external.
+    #
+    # def test_s_codepage
+    #   assert_equal(WIN32OLE::CP_ACP, WIN32OLE.codepage)
+    # end
 
     def test_s_codepage_set
       WIN32OLE.codepage = WIN32OLE::CP_UTF8

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]