• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Handling OS specific line breaks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling OS specific line breaks


  • Subject: Re: Handling OS specific line breaks
  • From: Chris Giordano <email@hidden>
  • Date: Mon, 20 May 2002 11:25:06 -0400

Varley,

Just a few thoughts. I'm by no means an expert on this -- I've seen discussion of related issues, and saw a parallel with BBEdit (Lite, actually, but I'd guess they work the same in this respect).

Two ways come to mind immediately: you can either treat all of your text view text in the same manner -- that is, translate to Unix line endings on load, and translate back to the original on save -- or you can make the text view better able to handle the line endings. For the latter, I'd guess that NSResponder's -(void)insertNewline:(id)sender method would be a good candidate for overriding. There is also the -(void)insertNewlineIgnoringFieldEditor:(id)sender. (Here is one of those areas where I don't have the experience to tell you which is appropriate, but I do see both of these in the documentation.) In your overridden method, you'd just insert whichever characters were appropriate for your file. Since NSTextView is a subclass of NSResponder, subclassing NSTextView and overriding one of these methods should give you the result you need. I haven't done this myself, but this looks like the way to go on this.

Or I guess a third option would be to allow the inconsistecy, and simply do some processing before saving, correcting any inconsistencies. You can just search for the other two options and replace them. These searches get a bit ugly since you have to correctly not replace parts of the DOS version -- someone managed to store a DOS file on our IBM mainframe (everything in EBCDIC), and bringing it over to my OS X machine results in very consistent garbage if done as a binary file, or in a file with blank lines between all of the lines due to replacing the "\r" in "\r\n" with "\n", giving "\n\n" at the end of every line.

Like I said, just a few thoughts.

chris



On Sunday, May 19, 2002, at 05:43 PM, Varley Taylor wrote:

I'm trying to figure out the best way to deal with OS specific text line breaks in a cocoa document based application.

It appears that text views appropriately account for displaying various flavors out there, e.g.:

Mac - \r (carriage return)
Unix - \n (new line)
DOS - \r\n (both)

However, editing within a text view seems to be a different story. It appears that hitting the return key within a text view always inserts a Unix style line break. The problem herein is that adding line breaks within a text view that contains non-Unix line breaks leads to line break type inconsistency. Perhaps I'm hallucinating... If not, does anyone know the best way around this?

Thanks in advance for any advice,
-Varley
_______________________________________________
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.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Handling OS specific line breaks
      • From: Douglas Davidson <email@hidden>
References: 
 >Handling OS specific line breaks (From: Varley Taylor <email@hidden>)

  • Prev by Date: OT: patent on wheel
  • Next by Date: Re: AwakeFromNib
  • Previous by thread: Handling OS specific line breaks
  • Next by thread: Re: Handling OS specific line breaks
  • Index(es):
    • Date
    • Thread