Should I Use std.ascii.isWhite or std.uni.isWhite?

Jonathan M Davis jmdavisProg at gmx.com
Thu Jul 25 22:06:24 PDT 2013


On Friday, July 26, 2013 06:09:39 Meta wrote:
> I'm confused about which isWhite function I should use. Aren't
> all chars in D (char, wchar, dchar) unicode characters? Should I
> always use std.uni.isWhite, unless I'm working with bytes and
> byte arrays? The documentation doesn't give me much to go on,
> beside "All of the functions in std.ascii accept unicode
> characters but effectively ignore them. All isX functions return
> false for unicode characters, and all toX functions do nothing to
> unicode characters."

Unicode contains ASCII, but very few Unicode characters are ASCII, because 
there just aren't very many ASCII characters and there and a _ton_ of Unicode 
characters. The std.ascii functions return true for certain sets of ASCII 
characters and false for everything else. The std.uni functions return true 
for many Unicode characters as well. You wouldn't normally use std.ascii if 
you're operating on non-ASCII Unicode characters, but it ignores them if it 
does run into them.

std.ascii.isWhite only cares about ASCII whitespace, which the documentation 
explicitly lists as the space, tab, vertical tab, form feed, carriage return, 
and linefeed characters. Those characters will return true. All other 
characters will return false.

std.uni.isWhite returns true for all of the characters that std.ascii.isWhite 
does plus a whole bunch of other non-ASCII characters that the Unicode 
standard considers to be whitespace.

Which function you use depends on what you're trying to do.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list