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: Gerben Wierda <email@hidden>
- Date: Wed, 24 May 2006 07:33:01 +0200
On 24 May 2006, at 01:52, Keary Suska wrote:
on 5/23/06 5:14 PM, email@hidden purportedly said:
If I have a NSFileHandle that reads from a unix subprocess the stderr
output (this is supposed to be readable output, say the output of a
gnutar command) what encoding do I use to turn the NSData I get with
availableData into an NSString (using initWIthData:encoding)?
The data is ascii, generally, but I cannot be sure there is no 8-bit
value in there. What happens if NSASCIIStringEncoding encounters
an 8-
bit value (say an accented character)?
I have been using NSUTF8StringEncoding so far because I read the docs
as that this was an 8 bit encoding. But I have been told that this is
wrong.
The short answer is that you need to use the encoding that the
source data
is encoded in. So once you know what encoding that is, that would
be the
encoding you use.
What I need is an encoding that allways works on all 8bit data thrown
at it and that since the data is text output from various unix
commands is most likely to give readable results. It may not fail and
produce a nil NSString when this is handed the data with
initWithData:encoding. The issue is that I cannot predict the coding
other than it is output generated on stderr/stdout from any unix-
level tool, meant to produce readable output, which may include 8-bit
characters.
I do not mind the accented characters are converted.
What I am worried about is that using UTF8 encoding may produce nil
(e.g. if the data contains byte 254 or 255) (if I understand the
UTF-8 encoding correctly because that is a flexible byte length
encoding).
Another way to phrase the question is: if I use initWithData:data
encoding:NSUTF8Encoding is it possible that I get nil as the result
if the NSData object contains random data?
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40rna.nl
This email sent to email@hidden
_______________________________________________
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