Re: How to convert a UTF-8 byte offset into an NSString character offset?
Re: How to convert a UTF-8 byte offset into an NSString character offset?
- Subject: Re: How to convert a UTF-8 byte offset into an NSString character offset?
- From: Uli Kusterer <email@hidden>
- Date: Wed, 07 May 2014 14:13:52 +0200
On 06 May 2014, at 20:12, Quincey Morris <email@hidden> wrote:
> FWIW, my opinion is that if your library clients are specifying UTF-8 sequences at the API, and expect byte offsets into those sequences to be meaningful, you might well be forced to maintain the original UTF-8 sequence in the library’s internal data model — or, perhaps, an array of the original code points — and do all of your internal processing in terms of code points. Conversion to NSString would happen only in the journey from data model to UI text field.
This is pretty much what I do in one of my projects. I hand-wrote code for converting between offsets, mostly based on tutorials from the net, knowing my offsets are always at the start/end of code points, and knowing that my conversion code always generates the same sequence, just encoding as UTF8/UTF16 as needed to display in the UI or convert selection offsets back to UTF8 offsets. The code hasn't shipped (or been tested much beyond myself using the app for a while), but if you're interested, contact me off-list and I'll send you a copy.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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