Re: What encoding to use to turn NSData from a subprocess into an NSString?
Re: What encoding to use to turn NSData from a subprocess into an NSString?
- Subject: Re: What encoding to use to turn NSData from a subprocess into an NSString?
- From: Annard Brouwer <email@hidden>
- Date: Wed, 24 May 2006 12:12:11 +0200
On 24 May 2006, at 08:32, Chris Suter wrote:
On 24/05/2006, at 4:15 PM, j o a r wrote:
On 24 maj 2006, at 07.56, Gerben Wierda wrote:
I do not really mind that the encoding is lossy, but I do not
want nil and I want as redable as possible results.
Perhaps you should prepare for nil results, and in that case
attempt fallback conversions with different encodings? This should
only be bad / expensive if your first choice for encoding is often
incorrect, something that you should be able to easily identify
and fix.
Aren't unix tools supposed to honour the LANG environment variable?
It's also worth checking that you get nil rather than an exception
(in the case where you get an invalid sequence of bytes for the
encoding you specify). You could always resort to using the CF
versions of the functions.
Indeed, you could check the environment variables that indicates the
language and encoding for shell processes (see "man locale"). Then I
would use CFStringConvertIANACharSetNameToEncoding() and
CFStringCreateFromExternalRepresentation() to convert the data. The
latter turned out to be much richer in the amount of supported
encodings than the one for NSString. In case anything goes wrong (and
this is still possible) you may need to create your own lossy
converter (map every byte with an int value < 128 to a char and
anything higher to a space or question mark) since I'm not sure if it
is available here.
Annard
_______________________________________________
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