Beispiel #1
0
        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;
        }
Beispiel #2
0
        public Location GetLocation(int charPositionInLine, int length)
        {
            var start  = Start + charPositionInLine;
            var extent = new TextExtent(start: start, length: length);

            return(SourceText.GetLocation(extent));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        LineRange GetLineRange(TextExtent extent)
        {
            var start = GetLinePositionAtPosition(extent.Start);
            var end   = GetLinePositionAtPosition(extent.End);

            return(new LineRange(start, end));
        }
Beispiel #5
0
 public Location(TextExtent extent, LineRange lineRange, [CanBeNull] string filePath)
 {
     Extent            = extent;
     StartLinePosition = lineRange.Start;
     EndLinePosition   = lineRange.End;
     FilePath          = filePath;
 }
Beispiel #6
0
        public static string Substring(this string text, TextExtent extent)
        {
            if (extent.IsMissing) {
                return String.Empty;
            }

            return text.Substring(startIndex: extent.Start, length: extent.Length);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
 public Location GetLocation(TextExtent extent)
 {
     return(new Location(extent, GetLineRange(extent), FileInfo?.FullName));
 }
Beispiel #9
0
 public ReadOnlySpan <char> Slice(TextExtent textExtent)
 {
     return(Slice(textExtent.Start, textExtent.Length));
 }
Beispiel #10
0
 public string Substring(TextExtent textExtent)
 {
     return(Substring(textExtent.Start, textExtent.Length));
 }
Beispiel #11
0
 public static TextChange NewReplace(TextExtent extent, string text)
 {
     return(new TextChange(extent, text));
 }
Beispiel #12
0
 public static TextChange NewRemove(TextExtent extent)
 {
     return(new TextChange(extent, String.Empty));
 }
Beispiel #13
0
 public static TextChange NewInsert(int position, string text)
 {
     return(new TextChange(TextExtent.FromBounds(position, position), text));
 }
Beispiel #14
0
 TextChange(TextExtent extent, string replacementText)
 {
     Extent           = extent;
     _replacementText = replacementText ?? throw new ArgumentNullException(nameof(replacementText));
 }
Beispiel #15
0
 public Location(TextExtent extent, LinePosition linePosition, [CanBeNull] string filePath) :
     this(extent, new LineRange(linePosition, linePosition), filePath)
 {
 }