Re: Tiger Decoding problem
Re: Tiger Decoding problem
- Subject: Re: Tiger Decoding problem
- From: Ondra Cada <email@hidden>
- Date: Mon, 30 May 2005 13:31:23 +0200
Nicholas,
On 30.5.2005, at 5:16, Nicholas Crosbie wrote:
I therefore tried the usedEncoding method, which I set
up as following (please comment if incorrect).
#import <Cocoa/Cocoa.h>
int main() {
[NSAutoreleasePool new];
NSString *path = @"/Users/nicholas/test2/fileB";
NSError *myLog = nil;
NSStringEncoding *guessEnc = nil;
NSStringEncoding is not an object, so declare it without a '*'
NSString *contents = [NSString
stringWithContentsOfFile:path usedEncoding:&guessEnc
error:&myLog];
(There should have been a warning here to point out the fact guessEnc
is not of a proper type.)
if (!contents) // could not read in the contents for
some reason: let us see the reason
NSLog(@"ERROR: %@",myLog); // which was filled into
myLog by the method
else /*all right*/ NSLog(@"OK: %@",contents);
return 0;
}
I get the same Run Log as when specifying an encoding.
Looks like the method just is not smart enough to determine the
encoding even for the simplest plain text files :) Well, don't be
surprised, since they write in the release notes that "these methods
might get "smarter" in subsequent releases of the system, and use
additional techniques for recognizing encodings" :))
22 /tmp> <q.m
#import <Cocoa/Cocoa.h>
int main() {
[NSAutoreleasePool new];
NSError *err;
NSStringEncoding enc;
NSString *contents=[NSString stringWithContentsOfFile:@"/tmp/q"
usedEncoding:&enc error:&err];
if (!contents) NSLog(@"ERROR: %@",err);
else NSLog(@"OK: %@",contents);
return 0;
}
23 /tmp> echo 'Whatever here...' > q
24 /tmp> cc -Wall -framework Cocoa q.m && ./a.out
2005-05-30 13:28:19.198 a.out[2657] ERROR: NSError "The file could
not be opened using specified text encoding."
Domain=NSCocoaErrorDomain Code=261 UserInfo={NSFilePath = "/tmp/q"; }
25 /tmp>
Let's wait till somebody from Apple comments on. Meantime, set the
encoding yourself using the original message (...encoding:...) and
some more general encoding (you can use TextEdit to try to open,
check the result, and thus to determine which encoding the file
actually uses).
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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