Accented Characters and Counting Syllables
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Dec 7 03:37:13 PST 2014
On Saturday, 6 December 2014 at 22:37:19 UTC, Nordlöw wrote:
> Given the fact that
>
> static assert("é".length == 2);
>
> I was surprised that
>
> static assert("é".byCodeUnit.length == 2);
> static assert("é".byCodePoint.length == 2);
string already iterates over code points. So byCodePoint doesn't
have to do anything on it, and it just returns the same string
again.
string's .length is the number of code units. It's not compatible
with the range primitives. That's why hasLength is false for
string (and wstring). Don't use .length on ranges without
checking hasLength.
So, while "é".byCodeUnit and "é".byCodePoint have equal
`.length`s, they have different range element counts.
More information about the Digitalmars-d-learn
mailing list