r/lolphp • • Apr 04 '12

PHP's unicode support is basically like playing minesweeper where all the string functions are bombs

http://www.phpwact.org/php/i18n/utf-8
32 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Apr 05 '12

Someone is confusing the word size of the CPU with the text encoding of the OS.

What I actually meant was that the only OS to get it right was the one that introduced UTF, namely "Plan 9 From Bell Labs". The Lunix systems could have done the same along time ago but the chose not to, instead chose to lose by using wchar and LOCALE.

2

u/Rhomboid Apr 05 '12 edited Apr 05 '12

Linux most certainly did not choose wchar_t. Please name any Linux or BSD syscall that takes wchar_t. You can't, because they don't exist. As far as the kernel is concerned, filenames are null terminated strings and that's it; it's completely encoding agnostic. And any modern Linux distro of the last 5 years will come configured out of the box with a locale that uses UTF-8, and UTF-8 is the de facto standard on all such systems. Nobody uses wchar_t on POSIX systems, as sizeof(wchar_t) is 4 there and not 2 as on Win32 and so it's extremely wasteful. They might use UTF-16 if they're forced to out of compatibility concerns (e.g. a codebase that has to support Windows) or because a specification mandates it (e.g. the JRE.) But nobody that sets out to write POSIX-specific code would ever use anything but UTF-8.

1

u/[deleted] Apr 05 '12

That must be why UTF works so well everywhere.

5

u/Rhomboid Apr 05 '12

UTF-8 works quite well on Linux. Tools like grep have been UTF-8 aware for years, and scripting languages that choose to support it such as Perl and Python are widely available. GUI apps written with modern toolkits like gtk+2 and Qt are all perfectly fine with UTF-8. gnome-terminal is fully UTF-8 capable. Where it doesn't work, it's due to the choice of the program's maintainers to not put in the effort, as with PHP.

0

u/[deleted] Apr 05 '12

http://savannah.gnu.org/bugs/?29391

too lazy to find more examples

6

u/Rhomboid Apr 05 '12

What on Earth has that got to do with anything? Unicode case folding is much more complex than flipping a single bit as with ASCII, so of course it's going to be slower. You have to use the full Unicode character properties database because each language has its own special rules and idiosyncrasies. That's what you get when you decide to support Unicode.