Thread overview
toString() for wchar*
Apr 27, 2004
Matthew
Apr 28, 2004
J Anderson
April 27, 2004
May I suggest adding the following functions to Phobos? I'm using them to convert strings from the Unicode versions of the Win32 API.


int strlen(wchar* s)
{
    int len = 0;
    wchar *c = &s[0];
    while (*c++) ++len;
    return len;
}

wchar[] toString(wchar* s)
{
    return s ? s[0 .. strlen(s)] : cast(wchar[])null;
}

This functions were converted from their "char" equivalents in std.string.


Thanks.


-- 
Julio César Carrascal Urquijo
April 27, 2004
> int strlen(wchar* s)
> {
>      int len = 0;
>      wchar *c = &s[0];
>      while (*c++) ++len;
>      return len;
> }

What's wrong with wcslen?

Or, if you want an overload,

    int strlen(wchar *s)
    {
        return wcslen(s);
    }

?


April 28, 2004
Matthew wrote:

>
>What's wrong with wcslen?
>  
>
Obviously wcslen is not obvious <g>

-- 
-Anderson: http://badmama.com.au/~anderson/
April 28, 2004
Matthew wrote:
> What's wrong with wcslen?
> 
> Or, if you want an overload,
> 
>     int strlen(wchar *s)
>     {
>         return wcslen(s);
>     }
> 
> ?
> 

Didn't knew it existed! Well I just really need the toString for wchars:

wchar[] toString(wchar* s)
{
    return s ? s[0 .. wcslen(s)] : cast(wchar[])null;
}


-- 
Julio César Carrascal Urquijo