Thanks!
Using the comparison  $name =~ m/^\0\0\0h/ solved the problem.


----- Original Message -----
From: Nick Ing-Simmons <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, January 30, 2001 4:30 AM
Subject: Re: Return Value comparison for const wchar_t*


> Manisha Mirajkar <[EMAIL PROTECTED]> writes:
> >Hi,
> >I am passing a const wchar_t* from a function MyFunc() in my XS file.
> >I have a custom typemap for const wchar_t*  :
> >
> >const wchar_t *         T_WCHAR
> >
> >INPUT
> >T_WCHAR
> >        $var = ($type)SvPV_nolen($arg)
> >
> >OUTPUT
> >T_WCHAR
> >        sv_setpv((SV*)$arg, (char *) $var, wcslen($var)*sizeof($type));
>
> A wide character is just that - _wide_ there will be a lot of nulls
> in the "string".
>
> >
> >In my perl script I want to do a string comparison where the first letter
is
> >say 'h'. My perl script is -
> >$Name = &Config::MyFunc();
> >print $Name;
> >if($Name =~ m/^h/)
> >{
> >    do something
> >}
>
> The clean way to do this in perl (IMHO) is to use perl5.6+ and UTF-8
encode
> your wide characters.
>
> The pattern would have to be (Assuming 32-bit big-endian wide character):
>
>      $name =~ m/^\0\0\0h/
>
> If little endian and 16-bit that would be /^h\0/ - which might have worked
> for a while.
>
> >
> >The $Name has a correct value as I see when I print it.
>
> Your terminal is probably ignoring the '\0's
>
>
> >But, the comparison
> >does not work!
> >The same thing works if the function returns a const char* which in my
> >typemap  is -
> >const char*     T_PV
> >
> >Is my typemap for const wchar_t* incorrect ?
>
> You cannot use perl's string operators on wide chars like that, they will
> work if you tell them about the nulls.
>
>
> >If yes, then how do I get a proper value when I print, and what could be
> >done so that the comparison works?
>
> Unicode, perl5.6+
>
> >
> >Thanks,
> >Manisha
> --
> Nick Ing-Simmons
>

Reply via email to