3 ms·
> Echoing back UTF-8 when you get UTF-8 input is handling binary, not handling text. Nope. UTF-8 is text. We don't live in an ascii world anymore, text require
by ars 15y ago
> Echoing back UTF-8 when you get UTF-8 input is handling binary, not handling text.
Nope. UTF-8 is text. We don't live in an ascii world anymore, text requires all 8 bits and a variable number of bytes per character.
> It won't work at all if you ever have any data sources or sinks that are not UTF-8
So don't do that. (Or convert as necessary.)
> and it won't work if you actually have to treat the data as text ("match all characters that are whitespace").
Wrong. Actually it works just fine.
> Yes, some PHP functions take binary blobs that contain UTF-8 octets and return correct-looking answers. That's all they do, though; that's handling UTF-8, not handling Unicode.
So? Since that's completely sufficient to do the job why do you want more?
> In Perl, characters are abstracted away from their character encoding.
Why? Why would I want to do that? Is this complexity for the sake of complexity?
> Your PHP method just assumes everything is UTF-8, which is simply not a safe assumption to make.
Yes, actually it is a safe assumption for the simple reason that the only types of strings I handle are UTF-8. In todays world there is no reason to use anything else. All other character sets are obsolete and should never be used.
And if you do need to handle one then convert as necessary, or define your app to handle only that character set. Programs that need to handle multiple character sets in the same applicate are extremely rare. There is no need for extreme complexity just to handle the rare case.
> Consider the case of binary data: if you start treating binary data like it's UTF-8 text, you break the binary data.
So don't do that.
> But change the locale to en_US.ISO-8859-1, and it doesn't work anymore.
So don't do that.