Re: Unicode replaceOccuranceOfString?
Re: Unicode replaceOccuranceOfString?
- Subject: Re: Unicode replaceOccuranceOfString?
- From: "M. Uli Kusterer" <email@hidden>
- Date: Sun, 19 Sep 2004 17:01:34 +0200
At 1:56 Uhr -0700 19.09.2004, Rachel Blackman wrote:
+ (NSString *) stringWithCharacterForUnicodeValue:(UniChar)character
{
// Make a CFString with our Unicode character...
CFMutableStringRef myRef =
CFStringCreateWithCharacters(NULL,&character,1);
// Create an NSString copy of it so we don't need to muck about
with CFRelease elsewhere in code.
NSString *charString = [NSString stringWithString:(NSString *)myRef];
// ...and free the CFString version.
CFRelease(myRef);
// I have a Unicode character!
return charString;
}
Ummm... are you aware that the whole stringWithString: part is
completely unnecessary? CFStringRefs can't just be passed in wherever
an NSString is expected, and vice versa; They *are* NSStrings for all
the computer cares.
Toll-free bridging works because a CFString is just a data structure
that looks just like an NSString does in memory. It even contains the
vtable pointer in the same position as it would be for an NSString.
So, all you'd need to do is:
NSString* str = (NSString*)
CFStringCreateWithCharacters(NULL,&character,1);
return [str autorelease];
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden