According to the link, the Unicode check (c & 0xC0) == 0x80 is only applied if strings are encoded in UTF-8. This PR fixes the character extraction from strings encoded in UTF-16.
Thanks for PR. Good catch.
Although, it seems, the code can be slightly optimized (e.g. double calling codePointAt for i=j), it works, has a test, and seems to be better than it was.
According to the link, the Unicode check
(c & 0xC0) == 0x80
is only applied if strings are encoded in UTF-8. This PR fixes the character extraction from strings encoded in UTF-16.