Get confused with initWithData:encoding:
Get confused with initWithData:encoding:
- Subject: Get confused with initWithData:encoding:
- From: Pierre Molinaro <email@hidden>
- Date: Tue, 2 Sep 2008 22:25:24 +0200
Hello,
I do not understand what I am doing wrong ; running the following
snippet:
NSMutableData * d = [NSMutableData dataWithCapacity:10] ;
const unsigned char data = 0xC0 ; // U+00CO is À
[d appendBytes:& data length:1] ;
NSLog (@"d: %@", d) ;
NSString * source = [[NSString alloc] initWithData:d
encoding:NSASCIIStringEncoding] ;
NSLog (@"source: [%@]", source) ;
const BOOL canBeConverted = [source
canBeConvertedToEncoding:NSASCIIStringEncoding] ;
NSLog (@"canBeConverted: '%@'", canBeConverted ? @"YES" : @"NO") ;
prints in the Debugger Console:
d: <c0>
source: [À]
canBeConverted: 'NO'
I do not understand why initWithData:encoding succeeds, as 0xC0 is not
a valid ASCII character.
The Cocoa doc says about NSASCIIStringEncoding: "Strict 7-bit ASCII
encoding within 8-bit chars; ASCII values 0…127 only”.
Then when I send canBeConvertedToEncoding: message to the string with
NSASCIIStringEncoding argument, the returned value is NO (correct !)
Could someone tell me why initWithData:encoding succeeds?
Thanks a lot.
Pierre
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden