News for hackers. Stuff that matters.
Re:Relive: 50 years of C, the good, the bad and the ugly by andsoitis on Saturday December 31, 2022 @11:25AM (#34197875)
This routine only works with ASCII, yea?
Re:Relive: 50 years of C, the good, the bad and the ugly by kazinator on Saturday December 31, 2022 @12:44PM (#34198732)
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.