wstring hex literals

Neia Neutuladh neia at ikeran.org
Wed Sep 20 16:26:46 UTC 2017


On Wednesday, 20 September 2017 at 15:04:08 UTC, jmh530 wrote:
> testing_utf16.d(5): Error: Truncated UTF-8 sequence
> testing_utf16.d(6):        while evaluating: static 
> assert((_error_) == (wstring
> ))
> Failed: ["dmd", "-unittest", "-v", "-o-", "testing_utf16.d", 
> "-I."]

https://dlang.org/spec/lex.html#hex_strings says:

> The string literals are assembled as UTF-8 char arrays, and the 
> postfix is applied to convert to wchar or dchar as necessary as 
> a final step.

This isn't the friendliest thing ever and is contrary to my 
expectations too. You basically have to encode your string into 
UTF-8 and then paste the hex of that in.

What should work is escape sequences:

     wstring str = "\u03c0"w;


More information about the Digitalmars-d-learn mailing list