Re: Line endings and dataRepresentationOfType
Re: Line endings and dataRepresentationOfType
- Subject: Re: Line endings and dataRepresentationOfType
- From: Dustin Voss <email@hidden>
- Date: Thu, 16 Oct 2003 16:49:44 -0700
On Thursday, October 16, 2003, at 02:36 AM, Chaffinch wrote:
Hi,
I am fairly new to Cocoa, and this is only my seconf app.
I have implemented dataRepresentationOfType to save my document and
that all
works fine. But I now want to be able to save using DOS (x0a, x0d) line
breaks. So I insert these into my document in the appropriate places
and pass
the resulting string to dataRepresentationOfType for saving.
But the resulting file still contains only the single x0d line break
character. Is dataRepresentationOfType stripping the extra x0a
character out
somewhere??
How can I save with DOS line endings, do I need to use the
writeToFile/readFromFile methods?
It seems to me that you are misunderstanding the
dataRepresentationOfType: method, or else expressing yourself poorly.
You don't pass strings to dataRepOfType to save them. What you pass is
the file format you want to save as. Your overridden dataRepOfType
accesses your document data and converts it appropriately. I'll assume
that is what you are doing.
The framework won't strip anything out of the data you return from
dataRepresentationOfType:. I'm guessing you are working on a simple
text editor that uses an NSTextStorage instance as the document (or
some other subclass of NSString). What your implementation of
dataRepresentationOfType: should do is call dataUsingEncoding: on that
string and return it.
I'm betting that the problem lies in how you insert the LF character
into the string, or how you convert the string to an NSData object. You
may need to convert the string line-by-line into NSData, and append the
two-byte line ending yourself.
_______________________________________________
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.