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

ruby-changes:36252

From: nobu <ko1@a...>
Date: Sun, 9 Nov 2014 12:09:49 +0900 (JST)
Subject: [ruby-changes:36252] nobu:r48333 (trunk): win32/registry.rb: slice in WCHARs

nobu	2014-11-09 12:09:40 +0900 (Sun, 09 Nov 2014)

  New Revision: 48333

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48333

  Log:
    win32/registry.rb: slice in WCHARs
    
    * ext/win32/lib/win32/registry.rb (Win32::Registry::API#Enum{Value,Key):
      ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32/lib/win32/registry.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48332)
+++ ChangeLog	(revision 48333)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Nov  9 12:09:38 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/win32/lib/win32/registry.rb (Win32::Registry::API#Enum{Value,Key):
+	  ditto.
+
 Sun Nov  9 11:48:40 2014  Tanaka Akira  <akr@f...>
 
 	* test/net/http: Examine webrick log.
Index: ext/win32/lib/win32/registry.rb
===================================================================
--- ext/win32/lib/win32/registry.rb	(revision 48332)
+++ ext/win32/lib/win32/registry.rb	(revision 48333)
@@ -66,6 +66,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L66
 
   WCHAR = Encoding::UTF_16LE
   WCHAR_NUL = "\0".encode(WCHAR).freeze
+  WCHAR_CR = "\r".encode(WCHAR).freeze
   WCHAR_SIZE = WCHAR_NUL.bytesize
   LOCALE = Encoding.find(Encoding.locale_charmap)
 
@@ -175,8 +176,10 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L176
         @code = code
         msg = WCHAR_NUL * 1024
         len = FormatMessageW.call(0x1200, 0, code, 0, msg, 1024, 0)
-        msg = msg[0, len].encode(LOCALE)
-        super msg.tr("\r".encode(msg.encoding), '').chomp
+        msg = msg.byteslice(0, len * WCHAR_SIZE)
+        msg.delete!(WCHAR_CR)
+        msg.chomp!
+        super msg.encode(LOCALE)
       end
       attr_reader :code
     end
@@ -290,7 +293,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L293
         name = WCHAR_NUL * Constants::MAX_KEY_LENGTH
         size = packdw(Constants::MAX_KEY_LENGTH)
         check RegEnumValueW.call(hkey, index, name, size, 0, 0, 0, 0)
-        name[0, unpackdw(size)]
+        name.byteslice(0, unpackdw(size) * WCHAR_SIZE)
       end
 
       def EnumKey(hkey, index)
@@ -298,7 +301,7 @@ For detail, see the MSDN[http://msdn.mic https://github.com/ruby/ruby/blob/trunk/ext/win32/lib/win32/registry.rb#L301
         size = packdw(Constants::MAX_KEY_LENGTH)
         wtime = ' ' * 8
         check RegEnumKeyExW.call(hkey, index, name, size, 0, 0, 0, wtime)
-        [ name[0, unpackdw(size)], unpackqw(wtime) ]
+        [ name.byteslice(0, unpackdw(size) * WCHAR_SIZE), unpackqw(wtime) ]
       end
 
       def QueryValue(hkey, name)

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

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