Re: NSAttributedString error.... [a solution]
Re: NSAttributedString error.... [a solution]
- Subject: Re: NSAttributedString error.... [a solution]
- From: "Steven M.Palm" <email@hidden>
- Date: Thu, 30 Jan 2003 11:11:44 -0600
On Thursday, January 30, 2003, at 10:03 AM, Steven M. Palm wrote:
When trying to us an NSAttributedString as follows:
attribText = [[NSAttributedString alloc] initWithHTML:[NSData
dataWithBytes:[myTextfield cString] length:[myTextField
cStringLength]] documentAttributes:NULL];
if (nil != attribText) {
sockprintf("%s\r\n\r\n", [[attribText string] cString]);
} else {
sockprintf("Plain text not available.\r\n\r\n");
}
I get the error in the Run Window of Project Builder:
Conversion to encoding 30 failed for string "30
\\u044f\\u043d\\u0432\\u0430\\u0440\\u044f 2003\\u0433. \\u2116 1..."
And my Application just sits there unresponsive until I kill it.
Neither case of the /if/ test is executed.
Unsure as of yet why the application just dies, but I was looking in
the wrong place for the cause of the error. It wasn't the
initialization of NSAttributedString that was causing the fault, it was
the conversion to a cString. By checking to make sure the string can be
converted to NSASCIIStringEncoding first, I avoid the error:
attribText = [[NSAttributedString alloc] initWithHTML:[NSData
dataWithBytes:[myTextfield cString] length:[myTextField cStringLength]]
documentAttributes:NULL];
if ((nil != attribText) && ([[attribText string]
canBeConvertedToEncoding:NSASCIIStringEncoding])) {
sockprintf("%s\r\n\r\n", [[attribText string] cString]);
[attribText release];
} else {
sockprintf("Plain text version not available for this
message.\r\n\r\n");
}
-----------------------
- Steven M. Palm
- Ham Radio Call: N9YTY
-----------------------
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.