[Win32utils-devel] Fwd: win32-clipboard and Unicode zero bytes

Daniel Berger djberg96 at yahoo.com
Wed Feb 1 19:39:47 EST 2006


Hi all,

I'm forwarding this message from Brian Marick.  If you
run this test script and then paste the results into a
Unicode aware text editor, you'll notice that it only
prints one character instead of three.

I tried changing the strlen to _tcslen and strcpy to
_tcscpy, but that didn't help.  I mucked around a bit
with the MultiByteToWideChar function, too, but didn't
have any luck.

Any ideas?

Thanks,

Dan 

# test.rb
$:.unshift Dir.pwd
require 'clipboard'

def unicopy(hex_name_array)
 
Win32::Clipboard.set_data(win32unicode(hex_name_array),
                           
Win32::Clipboard::UNICODETEXT)
  true
end


def extract_flipped_bytes(unicode_char_string)
  [unicode_char_string[2,2].to_i(16),
    unicode_char_string[0,2].to_i(16)]
end


def win32unicode(unicode_char_strings)
  flipped_bytes = unicode_char_strings.collect do |
str |
    extract_flipped_bytes(str)
  end
  flipped_bytes.flatten.pack('C*')
end

puts unicopy(%w{ 0401 0400 0402 })

Note: forwarded message attached.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An embedded message was scrubbed...
From: Brian Marick <marick at exampler.com>
Subject: win32-clipboard and Unicode zero bytes
Date: Mon, 30 Jan 2006 23:18:21 -0600
Size: 2677
Url: http://rubyforge.org/pipermail/win32utils-devel/attachments/20060201/0d798d05/attachment.eml


More information about the win32utils-devel mailing list