AvalonStudio.TextEditor.Document.TextUtilities.NormalizeNewLines C# (CSharp) Method

NormalizeNewLines() public static method

Normalizes all new lines in input to be newLine.
public static NormalizeNewLines ( string input, string newLine ) : string
input string
newLine string
return string
		public static string NormalizeNewLines(string input, string newLine)
		{
			if (input == null)
				return null;
			if (!IsNewLine(newLine))
				throw new ArgumentException("newLine must be one of the known newline sequences");
			var ds = NewLineFinder.NextNewLine(input, 0);
			if (ds == SimpleSegment.Invalid) // text does not contain any new lines
				return input;
			var b = new StringBuilder(input.Length);
			var lastEndOffset = 0;
			do
			{
				b.Append(input, lastEndOffset, ds.Offset - lastEndOffset);
				b.Append(newLine);
				lastEndOffset = ds.EndOffset;
				ds = NewLineFinder.NextNewLine(input, lastEndOffset);
			} while (ds != SimpleSegment.Invalid);
			// remaining string (after last newline)
			b.Append(input, lastEndOffset, input.Length - lastEndOffset);
			return b.ToString();
		}