コード例 #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;
        }
コード例 #2
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);
        }
コード例 #3
0
 public static TextChange NewInsert(int position, string text)
 {
     return(new TextChange(TextExtent.FromBounds(position, position), text));
 }