News for hackers. Stuff that matters.
Re:The string type is broken by jmpe on Wednesday November 27, 2013 @07:53AM (#6807764)
Had such a case a few months back. Strings of single-byte characters are Endian-agnostic but multi-byte character encoding is affected by Endianness. To cope with it I read the sequence as single byte, then reversed, then changed the encoding to proper encoding and reversed again. The data came from a binary dump where I only needed a section that contained a few strings.

I admit it's dirty but it was throwaway code for an isolated case.

Edit: eh, guys, as I stated the string came from a binary dump. I didn't get to choose the encoding, it came from ROM in an embedded system with a different Endianness. I had to figure out a way to make it human readable.

Re:The string type is broken by justincormack on Wednesday November 27, 2013 @08:11AM (#6807832)
Use UTF8, no endian issues. Thats yet another reason why UTF16 and UTF32 are broken.
Re:The string type is broken by monkeyninja on Wednesday November 27, 2013 @08:25AM (#6807878)
language will not store unicode string internally with UTF8. Yes, we use it as input and output, but in memory, utf8 is terrible for random access characters. endian is only an issue (normally) for input and output, not really an issue for internal storage. especially when using UTF16 and UTF32 you know exactly the size of items.
Re:The string type is broken by ygra on Wednesday November 27, 2013 @08:40AM (#6807956)
UTF-16 is just as bad as UTF-8 regarding variable-width code points. The only thing you always have (unless using compression schemes like SCSU) is random access to code units. Only UTF-32 also allows random access to code points. However, that's still of questionable value because when dealing with text you often want to handle graphemes, not code points, code units or bytes.
Re:The string type is broken by jeltz on Wednesday November 27, 2013 @08:31AM (#6807910)
You cannot do random access at all in Unicode, not even UTF-32 (and absolutely not UTF-16), due to combining characters.
Re:The string type is broken by jmdavis on Wednesday November 27, 2013 @08:44AM (#6807971)
UTF16 is variable length just like UTF8 is (so don't assume 2 bytes == 1 character).
Re:The string type is broken by jeltz on Wednesday November 27, 2013 @09:11AM (#6808078)
For this you do not need to reverse the string in a unicode aware way. You need to operate on the raw bytes.