recognizing asciiz, utf ...

Sergey Gromov snake.scaly at
Sun Mar 15 07:47:11 PDT 2009

Sun, 15 Mar 2009 05:20:08 -0400, newbee wrote:

> Sergey Gromov Wrote:
>> Fri, 13 Mar 2009 15:04:12 -0400, newbee wrote:
>>> How does one check for asciiz, utf ...? 
>>> I do get a buffer with characters as parameter in a function, but i
>>> don�t know if it is asciiz or utf or wchar. Is it possible to find
>>> out in dmd1 and dmd2? 
>> There is some redundancy in UTF-8 format so you can test if your string
>> is a valid UTF-8 string.  There is std.utf.validate() for you.  Any
>> ASCII string will also pass since ASCII is a special case of UTF-8.
>> Not all code points are defined in Unicode.  This means you can cast
>> your string to wchar[] and then test every char using the
>> std.utf.isValidDchar() function.  If it fails, then you definitely not
>> dealing with a valid wchar[] string, so test dchar[] similarly.
>> Be prepared though that these tests will sometimes give you false
>> positives.
> thank you kindly. this explanation really helped me. i will try that.

You're welcome.

I just realized that there are wchar[] and dchar[] versions of
std.utf.validate().  This should make your test really straight-forward.

More information about the Digitalmars-d-learn mailing list