2 ms·
It will also find ASCII characters in UTF-8. That's a common situation because delimiting characters are often in the ASCII range. We can make a more complica
by kazinator 4y ago
It will also find ASCII characters in UTF-8. That's a common situation because delimiting characters are often in the ASCII range.
We can make a more complicated example that nevertheless uses recursion and essentially the same way, which looks for a UTF-8 character. We can examine and decode a prefix of the string as a UTF-8. If there are bad bytes or the character doesn't match then we recurse.
We can also write a wide character (wchar_t) version of the function which looks the same. That will handle all of Unicode on sane platforms, and the basic multilingual plane (BMP) on Windows.