www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - toString() for wchar*

reply =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
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
Apr 27 2004
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
 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); } ?
Apr 27 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

What's wrong with wcslen?
  
Obviously wcslen is not obvious <g> -- -Anderson: http://badmama.com.au/~anderson/
Apr 27 2004
prev sibling parent =?ISO-8859-1?Q?Julio_C=E9sar_Carrascal_Urquijo?= writes:
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
Apr 28 2004