Unicode canonical decomposed form and text encoding
Unicode canonical decomposed form and text encoding
- Subject: Unicode canonical decomposed form and text encoding
- From: Renaud Boisjoly <email@hidden>
- Date: Mon, 13 Jan 2003 22:54:34 -0500
Hi all!
I'm trying to convert Unicode strings from the precomposed form to the
decomposed form (or the other way around) under 10.1
Under 10.2 I can use NSString's decomposedStringWithCanonicalMapping
method, which works fine.
But this is not supported under 10.1, which breaks my app.
Has anyone ever done this using Text Encoding COnverter or Unicode
Converter? Or perhaps by adapting GPL routines like GNOME's libunicode?
(
http://cvs.gnome.org/lxr/source/libunicode/decomp.h and
http://cvs.gnome.org/lxr/source/libunicode/decomp.c)
I've never adapted regular C routines like these to Onjective-C and my
experience is quite limited in that area. Same goes with Carbon
routines like TEC.
If anyone is willing to share their experience with this type of stuff,
it would really help me out.
Here's something I got from this list which does encoding conversions,
but I'm not sure how I'm supposed to call this function from my Cocoa
code... I used kTextEncodingMacUnicode instead of the one in the
original code, but I'm not sure if that is the right choice either...
+ (TECObjectRef) _unicodeID3v2ToMacTextConverter
{
static TECObjectRef id3v2ToMacTextConverter = NULL;
if (id3v2ToMacTextConverter == NULL) {
OSStatus status;
status = TECCreateConverter(&id3v2ToMacTextConverter,
kTextEncodingMacUnicode,
kTextEncodingUnicode);
if (status != 0) {
NSLog(@"TECCreateConverter() error %d", status);
return nil;
}
}
return id3v2ToMacTextConverter;
}
+ (CFStringRef /* implies caller retain */) _convertUnicodeText:
(ConstTextPtr) textBuffer ofLength:
(unsigned int) length
{
ByteCount actualInputConsumed;
ByteCount actualOutputProduced;
UInt8 outputBuffer[1024];
CFMutableStringRef returnString = CFStringCreateMutable(NULL, 0);
TECObjectRef textConverter = [self _unicodeID3v2ToMacTextConverter];
do {
OSStatus status;
status = TECConvertText(textConverter, textBuffer, length,
&actualInputConsumed, outputBuffer,
sizeof(outputBuffer),
&actualOutputProduced);
if (status != 0) {
NSLog(@"TECConvertText() error %d", status);
return nil;
}
CFStringAppendCharacters(returnString, (const UniChar
*)outputBuffer, actualOutputProduced);
length = length - actualInputConsumed;
textBuffer = textBuffer + actualInputConsumed;
} while (length > 0);
return returnString;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.