Encoding issues
Encoding issues
- Subject: Encoding issues
- From: "Hell's KItchen Hell's KItchen" <email@hidden>
- Date: Fri, 1 Dec 2006 16:29:53 +0100
Hello list,
I've made a program that reads message from a server. Each message arrive as
7bit ASCII encoding (as like in irc...). Each message contains a key that
indicate what kind of encoding is used inside the message. Now I need to
take the message, save it into a file and then read it again using WebKit
(the message string is placed in an XML file and with an XSL transform I get
an HTML UFT8 -into the page headers- document).
Now the problem is that not works as I would.
Each message from server is taken from an NSData, encoded as
NSISOLatin1StringEncoding and then saved to a file.
When I read it again I take NSData from server, transform it to
NSISOLatin1StringEncoding and place it to an NSString.
Well now I try to read the header of the message to see what encoding is
used into the body.
Suppose to have UTF8 Encoding.
NSData *data = [str dataUsingEncoding: NSISOLatin1StringEncoding
allowLossyConversion: YES]
NSString *txt = [[[NSString alloc] initWithData: data
encoding:CFStringConvertEncodingToNSStringEncoding([contentType
nfCFStringEncoding])] autorelease];// NSUTF8StringEncoding];
return txt;
contentType contains the encoding type.
This is the method used to get str variable (the string inside my file):
- (NSString *) getTextDataInRange:(NSRange) _rg {
NSFileHandle *dt = [self _getDataHandle];
[dt seekToFileOffset: _rg.location];
NSString *str = [[NSString alloc] initWithData: [dt
readDataOfLength:_rg.length] encoding: NSISOLatin1StringEncoding];
return [str autorelease];
}
However the final results is wrong. WebKit render for example, the letter รจ
(e') to A-and-another char (two chars, as like UTF8....but I should render
it!).
What's wrong in my code?
I've also tried to read NSData from file and then convert it to
NSUTF8Encoding:
- (NSData *) getDataInRange:(NSRange) _rg {
NSFileHandle *dt = [self _getDataHandle];
[dt seekToFileOffset: _rg.location];
NSData *data = [[NSData alloc] initWithData: [dt
readDataOfLength:_rg.length]];
return [data autorelease];
}
and then
NSData *data = [self getDataInRange: _rg];
NSString *txt = [[[NSString alloc] initWithData: data
encoding:CFStringConvertEncodingToNSStringEncoding([contentType
nfCFStringEncoding])] autorelease];// NSUTF8StringEncoding];
But it still not works (in this case the results string is nil).
Anyone can help me?
Thank you a lot
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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