AppKit.TextKit.Formatter.LanguageFormatter.FindStartOfLine C# (CSharp) Method

FindStartOfLine() public method

Finds the start of line for the given location in the text as defined by the NewLine, LineSeparator and ParagraphSeparator characters.
public FindStartOfLine ( string text, NSRange position ) : NSRange
text string The text to find the start of the line in.
position NSRange The current location of the cursor in the text and possible selection.
return NSRange
		public virtual NSRange FindStartOfLine(string text, NSRange position) {
			NSRange results = new NSRange(position.Location, position.Length);
			var found = false;

			// Find starting line boundry
			while(results.Location > 0 && !found) {
				var c = text [(int)results.Location - 1];
				found = (c == Newline || c == LineSeparator || c == ParagraphSeparator);
				if (!found) results.Location -= 1;
			};

			// Calculate length
			results.Length = position.Location - results.Location;

			return results;
		}