4 ms·
It's important to note that choice of language affects a lot of these issues. For example, the unicode issue in Python: >>> s = unicode('Les Misérables','utf
by mumrah 17y ago
It's important to note that choice of language affects a lot of these issues. For example, the unicode issue in Python:
>>> s = unicode('Les Misérables','utf-8')
>>> print s[::-1]
selbarésiM seL
- gord 17y agoI think the s is round the wrong way.
- blasdel 17y agoNope, Python fucks this up just the same, even in Python 3: >>> print u'Les Mise\u0301rables'[::-1] #2 >>> print('Les Mise\u0301rables'[::-1]) #3 selbaŕesiM seL Almost no implementation will fuck up LATIN SMALL LETTER E WITH ACUTE U+00E9, but nearly all programming languages will royally fuck up a COMBINING ACUTE ACCENT U+0301 even in much easier cases like string length. Almost all implementations that claim to be UTF-16 are actually UCS-2, and can't handle surrogates in the slightest.
- stilist 17y agoHere’s a good series of articles on how it works in Ruby: http://blog.grayproductions.net/categories/character_encodings http://blog.grayproductions.net/categories/character_encodin... Apparently Ruby 1.9 handles it well. (I wouldn’t be surprised if this had previously been linked on HN.)
- simonw 17y agoYou can get the correct result by normalizing the string first: >>> import unicodedata >>> print unicodedata.normalize('NFC', u'Les Mise\u0301rables')[::-1] selbarésiM seL
- deleted 17y ago[deleted]
- fh 17y agoThat's in some sense even more broken: Not all combined characters have a normalized form, so the result is even less predictable. (I don't have an example ready.)