[haiku-commits] Re: r41084 - haiku/trunk/src/kits/support

  • From: Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 23 Mar 2011 11:20:52 +0100

On 2011-03-23 at 10:52:37 [+0100], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> 
> clemens.zeidler@xxxxxxxxxxxxxx wrote:
> > -    int32 startCount = 0;
> > -    while (isspace(string[startCount]))
> > +    // string is \0 terminated thus we don't need to check if we reached 
> > the
> > end
> > +    uint32 startCount = 0;
> > +    while (iswspace(string[startCount]))
> You aren't using iswspace() correctly, it can't do anything with "char"s, 
> it needs wide characters to work with.
> IIRC libbe.so already links against liblocale.so, right? If so, you could 
> just take advantage of the BUnicodeChar class, otherwise, you need to 
> translate the string first.

Exactly, and you'd have to translate the string to unicode code points 
(sometimes named ISO-10646, UCS-4 or UTF-32), since that's what wchar_t is 
expected to contain on Haiku. Some other OSes (e.g. Windows) use UTF-16 here, 
but Haiku follows glibc in that regard and uses 32-bit code points.
But precisely because of this implicit assumption of what wchar_t contains, 
the conversion would have to involve one of the mbr... (multibyte) functions. 
In general, I recommend we should keep clear of all those moronic wchar_t/mbr 
functions, as they do not make much sense (except for ports using them). 

Instead, please use BUnicodeChar to check for all whitespace characters.

In order to do so, liblocale.so needs to be merged with libbe.so, though, as 
currently there's only a cumbersome, dynamically loaded backend access from 
libbe to liblocale available.

As an alternative, you could just revert to using isspace() and we take care 
of this minor problem when we make BString generally unicode-aware. 


Other related posts: