diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-09 03:09:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-11-09 03:09:40 +0000 |
commit | 0066d95fd6b679a90ba8e62d17e535127e3a4860 (patch) | |
tree | 6dfa063d026c44a449c29401466351b477d8a7c4 /ext | |
parent | 0babd248270c0e108ef593b36d0fd188c966ecbb (diff) | |
download | ruby-0066d95fd6b679a90ba8e62d17e535127e3a4860.tar.gz |
win32/registry.rb: slice in WCHARs
* ext/win32/lib/win32/registry.rb (Win32::Registry::API#Enum{Value,Key):
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/win32/lib/win32/registry.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/win32/lib/win32/registry.rb b/ext/win32/lib/win32/registry.rb index 74cc77dc9f..b14bd48fcf 100644 --- a/ext/win32/lib/win32/registry.rb +++ b/ext/win32/lib/win32/registry.rb @@ -66,6 +66,7 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr 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.microsoft.com/library/en-us/sysinfo/base/pr @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.microsoft.com/library/en-us/sysinfo/base/pr 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.microsoft.com/library/en-us/sysinfo/base/pr 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) |