[Win32utils-devel] Problems with win32-dir and create_junction

Berger, Daniel Daniel.Berger at qwest.com
Wed Oct 15 17:48:59 EDT 2008


Hi, 

> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org 
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of 
> Heesob Park
> Sent: Thursday, October 02, 2008 8:25 AM
> To: Development and ideas for win32utils projects
> Subject: Re: [Win32utils-devel] Problems with win32-dir and 
> create_junction
> 
> 2008/10/2 Berger, Daniel <Daniel.Berger at qwest.com>:
> >> -----Original Message-----
> >> From: win32utils-devel-bounces at rubyforge.org
> >> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf 
> Of Berger, 
> >> Daniel
> >> Sent: Thursday, October 02, 2008 8:12 AM
> >> To: Development and ideas for win32utils projects
> >> Subject: Re: [Win32utils-devel] Problems with win32-dir and 
> >> create_junction
> >
> > <snip>
> >
> >> Do you think we should automatically strip the trailing 
> "\000\000" in 
> >> the multi_to_wide method then? I think this would work because I 
> >> modified wide_to_multi to automatically append "\000\000" to the 
> >> incoming string if they weren't already there.
> >
> > On second thought, I think that might cause wide character 
> functions 
> > to fail.
> >
> I think it would be better to define new method for getting 
> the wide_string length than to use String#size method.

Here's a minimal WideString class:

   require 'windows/unicode'
   require 'windows/msvcrt/string'

   class WideString < String
      include Windows::Unicode
      include Windows::MSVCRT::String
   
      ACP  = CP_ACP
      UTF7 = CP_UTF7
      UTF8 = CP_UTF8
   
      attr_accessor :encoding
   
      def initialize(string, encoding = UTF8)
         super(multi_to_wide(string, encoding))
         @encoding = encoding
      end
   
      def length
         wcslen(self) * 2      
      end

      alias size length   
   end

Another approach is to monkey-patch String:

   require 'windows/msvcrt/string'

   class String
      include Windows::MSVCRT::String
      def wlength
         wcslen(self) * 2
      end
      alias wsize wlength
   end

What do you think?

Regards,

Dan


This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly 
prohibited and may be unlawful.  If you have received this communication 
in error, please immediately notify the sender by reply e-mail and destroy 
all copies of the communication and any attachments.


More information about the win32utils-devel mailing list