Re: Reversing a String
Re: Reversing a String
- Subject: Re: Reversing a String
- From: Ricky Sharp <email@hidden>
- Date: Wed, 31 Dec 2008 12:09:02 -0600
On Dec 31, 2008, at 10:52 AM, Michael Ash wrote:
The key is the usage of -rangeOfComposedCharacterSequenceAtIndex:.
Without calling this method or doing the equivalent to what it does,
your code will suffer the problems I described above.
I tested that code with the string @"abcdéf𝄞g" (that's an
accented e
using a combining diacritical before the f, and the aforementioned
musical note at the end) and it worked as expected.
I don't guarantee that my code will work on everything. Unicode is
weird enough and covers enough weird languages that there are probably
situations where this will still fail. But it covers most of the
tricky bits, and at least will always produce valid unicode output.
Reversing a string only really makes sense for certain languages
anyhow. Perhaps even just English. The rendering of reversed strings
may also get a bit weird for text involving positional variants.
Anyhow, attempting to construct a universal solution will either be
too difficult or perhaps not possible. The original poster should
provide some extra clues as to what the output will be used for.
I'm all for 100% Unicode support by applications, but there are some
situations where working with plain 'ol ASCII still makes sense. In
that specific case, reversing a string becomes trivial.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden