in reply to Re: Win32::API and CreateProcessWithLogonW
in thread Win32::API and CreateProcessWithLogonW

I convert between UTF-16LE (not "UTF8LE" as you wrote) and ASCII or UTF-8 using pack rather simply:

$utf16= pack "S*", unpack( "C*", $ascii ), 0; $utf16= pack "S*", unpack( "U*", $utf8 ), 0; $ascii= pack "C*", unpack( "S*", $utf16 ); $ascii =~ s/\0$//; $utf8 = pack "U*", unpack( "S*", $utf16 ); $utf8 =~ s/\0$//;

but note that this doesn't handle extra large Unicode code points (which Windows doesn't handle by default either but can be configured to support at least partially).

To feel less hackish, one would likely use the Encode module, which can probably also handle the characters in the Windows-1252 extensions to Latin-1.

- tye        

Replies are listed 'Best First'.
Re^3: Win32::API and CreateProcessWithLogonW
by BrowserUk (Patriarch) on Jan 30, 2007 at 07:15 UTC

    I have a couple of similar routines I use for myself, but I'm reluctant to recommend to others, because of the ire they are likely to draw:

    sub A2W{ pack 'S*', unpack 'C*', $_[0] } sub W2A{ pack 'C*', unpack 'S*', $_[0] }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I only see two problems. 1) They don't handle the few characters that are in Windows-1252 but not Latin-1. 2) They don't handle the trailing "\0\0" that is needed on the end of wide strings. (1) certainly hasn't bothered me enough to jump through other hoops very often. (2) can be a real problem in some situations and no problem at all in others.

      Oh, and problem (1) that I also mentioned regarding my versions isn't actually a problem for the UTF-18LE / UTF-8 versions; it is just a problem with "ASCII" versions (which really convert to/from Latin-1), now that I think of it.

      - tye