• 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: alphabetical sorting, and line breaks in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alphabetical sorting, and line breaks in NSTextView


  • Subject: Re: alphabetical sorting, and line breaks in NSTextView
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 28 Jun 2006 08:36:39 -0700


On Jun 27, 2006, at 11:28 PM, email@hidden wrote:

I'm trying to add "alphabetical sorting of lines" (as in TextWrangler) in
my NSDocument&NSTextView-based Cocoa app. A first step would be to create
a function sortAlphabetically that takes an NSString, scans it using "\n"
as a separator
and sorts the lines : e.g.


sortAlphabetically(@"noun\nzoo\nadder\nvoid")=@"adder\nnoun\nvoid \nzoo"

The problem is, not all line breaks are like this;
most of them are made automatically by the application when the end of the
line is reached on the current UI. How does the NSTextView architecture
keep track
of those other line breaks ?



Use NSString methods such as lineRangeForRange:, paragraphRangeForRange:, getLineStart:end:contentsEnd:forRange:, or getParagraphStart:end:contentsEnd:forRange:. The difference between the "line" methods and the "paragraph" methods is that there are characters that count as line breaks but not paragraph breaks, most notably the Unicode line separator U+2028. The difference between the range-for-range methods and the get methods is that the latter allow you to distinguish between the contents of the line and the break at the end of it; this is important because not all breaks are the same length (\r\n is two characters) and because the last line may not have a break at the end.


Douglas Davidson


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >alphabetical sorting, and line breaks in NSTextView (From: email@hidden)

  • Prev by Date: how do load PDFs without the PDFKit?
  • Next by Date: Relative NSDate Description
  • Previous by thread: alphabetical sorting, and line breaks in NSTextView
  • Next by thread: calling nibtool in Objective-C code ?
  • Index(es):
    • Date
    • Thread