AvalonStudio.TextEditor.Document.NewLineFinder.NextNewLine C# (CSharp) Method

NextNewLine() static private method

Gets the location of the next new line character, or SimpleSegment.Invalid if none is found.
static private NextNewLine ( ITextSource text, int offset ) : SimpleSegment
text ITextSource
offset int
return SimpleSegment
		internal static SimpleSegment NextNewLine(ITextSource text, int offset)
		{
			var textLength = text.TextLength;
			var pos = text.IndexOfAny(newline, offset, textLength - offset);
			if (pos >= 0)
			{
				if (text.GetCharAt(pos) == '\r')
				{
					if (pos + 1 < textLength && text.GetCharAt(pos + 1) == '\n')
						return new SimpleSegment(pos, 2);
				}
				return new SimpleSegment(pos, 1);
			}
			return SimpleSegment.Invalid;
		}
	}

Same methods

NewLineFinder::NextNewLine ( string text, int offset ) : SimpleSegment

Usage Example

Example #1
0
        /// <summary>
        ///     Normalizes all new lines in <paramref name="input" /> to be <paramref name="newLine" />.
        /// </summary>
        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());
        }
All Usage Examples Of AvalonStudio.TextEditor.Document.NewLineFinder::NextNewLine
NewLineFinder