On Aug 25, 2009, at 7:21 PM, Ross Carter wrote:

I haven't tried it, but this should work:

        NSAttributedString* original = whatever;
NSMutableAttributedString* normalized = [[original mutableCopy] autorelease]; CFMutableStringRef str = (CFMutableStringRef)[original mutableString];
        CFStringNormalize(str, kCFStringNormalizationFormD);

This works because -[NSMutableAttributedString mutableString] is a proxy that automatically fixes up the attribute runs held by its owner.

~Martin


Brilliant! Works just like you said. Thanks, Martin.

Hmm, this seems dangerous in the sense that the conversion may be lossy. As far as I can see, there's no guarantee that CFStringNormalize will perform minimal replacements. If it does not, then whole ranges of characters may have their attributes reset to that of the first replaced character.

Even if testing reveals it to be non-lossy under one testing environment, without a guarantee that might differ under any other testing environment.

Also, it should be self-evident that normalizing to a precomposed form will obliterate attribute differences between a base character and any combining characters, as discussed elsewhere in this thread.

All that said, I'm still unclear why the string is being normalized to begin with. Why does the archive require (if it does) that the string be in normalized form? It doesn't seem necessary for the unarchival process. If you're anticipating some other tool working with the data in the meantime, then how will that tool work with the attributes? If the other tool will modify the string data, then your attributes won't reapply properly on unarchival.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to