On Sunday, 25 August 2013 at 19:38:52 UTC, Paolo Invernizzi wrote:
On Sunday, 25 August 2013 at 19:25:08 UTC, qznc wrote:
Apparently, ElementType!string evaluates to dchar. I would
have expected char. Why is that?
I think is because they are iterated by ranges as dchar, that's
equivalent to iterating the unicode symbol.
If they were iterated by char, you would get during the
iteration the singles pieces of the utf8 encoding, and usually
that is not what an user is expecting.
Note on the other side that static assert( is(typeof(" "[0]) ==
immutable(char)) ), so you can iterate the string by chars
using the index.
- Paolo Invernizzi
Thanks, somewhat unintuitive.
This also seems to the explanation, why the types documentation
decribes char as "unsigned 8 bit UTF-8", which is different than
ubyte "unsigned 8 bit".
Confirmed by this unittest:
string raw = "Maß";↵
assert(raw.length == 4);↵
assert(walkLength(raw)== 3);