Re: ISO 8859-15 (Latin 9) Euro symbol and more
Re: ISO 8859-15 (Latin 9) Euro symbol and more
- Subject: Re: ISO 8859-15 (Latin 9) Euro symbol and more
- From: Bertrand Mansion <email@hidden>
- Date: Sun, 25 Jul 2004 19:45:55 +0200
Chuck Soper wrote:
>
At 2:14 PM -0600 7/24/04, Nick Zitzmann wrote:
>
>On Jul 24, 2004, at 1:37 PM, Bertrand Mansion wrote:
>
>
>
>>I have to use the euro symbol and other chars (& -> oe for example) which are
>
>>available in the ISO 8859-15 character set [1] but this encoding
>
>>does not seem
>
>>to be available as a NSStringEncoding. Unfortunately, using Unicode is not an
>
>>option for me due to compatibility reasons with the underlying library.
>
>>
>
>>I have also noticed that the Core Foundation seems to have more encodings
>
>>available than Cocoa. Is this an option ? If yes, what would be the
>
>>best way to
>
>>convert from one to another ? Which other solutions could I try ?
>
>
>
>Yes. CoreFoundation has a lot of string encodings that aren't
>
>present in the NSString.h header, but that doesn't mean there aren't
>
>more NSString encodings you can use. If you look at CFString.h,
>
>you'll notice that there's a function called
>
>CFStringConvertEncodingToNSStringEncoding() that bridges this gap. I
>
>haven't tried it with that particular encoding you've mentioned, but
>
>that would be the first thing I'd try.
>
>
kCFStringEncodingISOLatin9 is defined in CFStringEncodingExt.h
>
I think that you may have to use this NSString initializer:
>
- (id)initWithData:(NSData *)data encoding:(NSStringEncoding)encoding with
>
NSProprietaryStringEncoding, but I really don't know. If you find a
>
way to convert the encoding please post your results.
Here is the function I came up with but I don't know Carbon and CF at all so it
might leak or even not function correctly so any input on if I should use
CFRelease or save a CFStringGetBytes() call are welcome :)
<code>
+ (id)myStringWithCString:(const char *)cString
encoding:(CFStringEncoding)encoding
{
CFStringEncoding srcEncoding = CFStringGetSystemEncoding();
CFStringRef str = CFStringCreateWithCString(NULL, cString, srcEncoding);
CFRange rangeToProcess = CFRangeMake(0, CFStringGetLength(str));
CFIndex usedBufferLength;
CFIndex numChars = CFStringGetBytes(str, rangeToProcess, encoding, '?',
FALSE, NULL, 0, &usedBufferLength);
if (numChars > 0) {
UInt8 localBuffer[(int)usedBufferLength];
CFStringGetBytes(str, rangeToProcess, encoding, '?', FALSE,
(UInt8 *)localBuffer, usedBufferLength, NULL);
return [NSString stringWithCString:localBuffer length:usedBufferLength];
}
return [NSString stringWithString:@""];
}
</code>
Thanks for your help.
Bertrand Mansion
Mamasam
http://www.cocoabuilder.com
_______________________________________________
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.