views:

187

answers:

1

This document by Apple Technical Q&A QA1235 describes a way to convert unicode strings from a composed to a decomposed version. Since I have a problem with file names containing some characters (e.g. an accent grave), I'd like to try the conversion function

void CFStringNormalize(CFMutableStringRef theString, CFStringNormalizationForm theForm);

I am using this with Python and the AppKit library. If i pass a Python String as an argument, I get:

CoreFoundation.CFStringNormalize("abc",0) 2009-04-27 21:00:54.314 Python[4519:613] * -[OC_PythonString _cfNormalize:]: unrecognized selector sent to instance 0x1f02510 Traceback (most recent call last): File "", line 1, in ValueError: NSInvalidArgumentException - * -[OC_PythonString _cfNormalize:]: unrecognized selector sent to instance 0x1f02510

I suppose this is because a CFMutableStringRef is needed as an argument. How do I convert a Python String to CFMutableStringRef?

+1  A: 

OC_PythonString (which is what Python strings are bridged to) is an NSString subclass, so you could get an NSMutableString with:

mutableString = NSMutableString.alloc().initWithString_("abc")

then use mutableString as the argument to CFStringNormalize.

smorgan