internal SourceTextLine(StringSourceText sourceText, int line, int lineStart, int lineEnd) { if (sourceText == null) { throw new ArgumentNullException(nameof(sourceText)); } if (TextExtent.FromBounds(lineStart, lineEnd).IsMissing) { throw new ArgumentOutOfRangeException(nameof(lineEnd)); } if (line < 0) { throw new ArgumentOutOfRangeException(nameof(line)); } if (line > lineEnd) { throw new ArgumentOutOfRangeException(nameof(line)); } if (lineEnd > sourceText.Length) { throw new ArgumentOutOfRangeException(nameof(lineEnd)); } SourceText = sourceText; Line = line; Start = lineStart; EndIncludingLineBreak = lineEnd; }
public Location GetLocation(int charPositionInLine, int length) { var start = Start + charPositionInLine; var extent = new TextExtent(start: start, length: length); return(SourceText.GetLocation(extent)); }
public static TextExtent QuotedExtent(this ReadOnlySpan<char> text, int position, char quotationChar = '"', bool includequotationCharInExtent = false) { if (!IsInTextBlockImpl(text, position, quotationChar, out var start)) { return TextExtent.Missing; } int offset = 0; if (includequotationCharInExtent) { offset = 1; } start++; int firstWhiteSpace = -1; for (int index = start; index < text.Length; index++) { if (text[index] == quotationChar) { return TextExtent.FromBounds(start: start - offset, end: index + offset); } if (firstWhiteSpace == -1 && Char.IsWhiteSpace(text[index])) { firstWhiteSpace = index; } } if (firstWhiteSpace != -1) { return TextExtent.FromBounds(start: start - offset, end: firstWhiteSpace); } return TextExtent.FromBounds(start: start - offset, end: text.Length); }
LineRange GetLineRange(TextExtent extent) { var start = GetLinePositionAtPosition(extent.Start); var end = GetLinePositionAtPosition(extent.End); return(new LineRange(start, end)); }
public Location(TextExtent extent, LineRange lineRange, [CanBeNull] string filePath) { Extent = extent; StartLinePosition = lineRange.Start; EndLinePosition = lineRange.End; FilePath = filePath; }
public static string Substring(this string text, TextExtent extent) { if (extent.IsMissing) { return String.Empty; } return text.Substring(startIndex: extent.Start, length: extent.Length); }
public static ReadOnlySpan<char> Slice(this ReadOnlySpan<char> span, TextExtent extent) { if (extent.IsMissing) { return ReadOnlySpan<char>.Empty; } return span.Slice(start: extent.Start, length: extent.Length); }
public Location GetLocation(TextExtent extent) { return(new Location(extent, GetLineRange(extent), FileInfo?.FullName)); }
public ReadOnlySpan <char> Slice(TextExtent textExtent) { return(Slice(textExtent.Start, textExtent.Length)); }
public string Substring(TextExtent textExtent) { return(Substring(textExtent.Start, textExtent.Length)); }
public static TextChange NewReplace(TextExtent extent, string text) { return(new TextChange(extent, text)); }
public static TextChange NewRemove(TextExtent extent) { return(new TextChange(extent, String.Empty)); }
public static TextChange NewInsert(int position, string text) { return(new TextChange(TextExtent.FromBounds(position, position), text)); }
TextChange(TextExtent extent, string replacementText) { Extent = extent; _replacementText = replacementText ?? throw new ArgumentNullException(nameof(replacementText)); }
public Location(TextExtent extent, LinePosition linePosition, [CanBeNull] string filePath) : this(extent, new LineRange(linePosition, linePosition), filePath) { }