Why ElementType!(char[3]) == dchar instead of char?
Justin Whear via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 1 10:00:20 PDT 2015
On Tue, 01 Sep 2015 19:40:24 +0300, drug wrote:
> I'm just trying to automatically convert D types to hdf5 types so I
> guess char[..] isn't obligatory some form of UTF-8 encoded text. Or I
> should treat it so?
Because of D's autodecoding it can be problematic to assume UTF-8 if
other encodings are actually in use. If, for instance, you try printing
a string stored as char[] that is actually Latin-1 encoded and contains
characters from the high range, you'll get a runtime UTF-8 decoding
exception. If you don't know ahead of time what the encoding will be,
using ubyte[] will be safer. The other option is to dynamically reencode
strings to UTF-8 as you read them.
More information about the Digitalmars-d-learn
mailing list