Skip navigation.
 
mlRe: NSAttributedString error.... [a solution]
FROM : Steven M.Palm
DATE : Thu Jan 30 18:11:44 2003

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_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mlNSAttributedString error.... Steven M.Palm Jan 30, 17:03
mlRe: NSAttributedString error.... [a solution] Steven M.Palm Jan 30, 18:11
mlRe: NSAttributedString error.... [a solution] Sherm Pendley Jan 30, 20:17
mlRe: NSAttributedString error.... Aki Inoue Jan 30, 20:46