コード例 #1
0
 /// <summary>
 /// Return a fragment of a text line, safely ensuring that "start" and "end" position are within the boundaries
 /// of the line. |options| can be used to customize the behavior.
 /// </summary>
 public static TextLineFragment GetFragment(
     this ITextSnapshotLine line,
     int start,
     int end,
     TextLineFragment.Options options)
 {
     return(TextLineFragment.Create(line, start, end, options));
 }
コード例 #2
0
        /// <summary>
        /// Return a fragment of a text line, safely ensuring that "start" and "end" position are within the boundaries
        /// of the line. |options| can be used to customize the behavior.
        /// </summary>
        public static TextLineFragment Create(ITextSnapshotLine line, int start, int end, TextLineFragment.Options options)
        {
            if (start < line.Start.Position)
            {
                start = line.Start.Position;
            }

            if ((options & TextLineFragment.Options.IncludeLineBreak) == TextLineFragment.Options.IncludeLineBreak)
            {
                if (end > line.EndIncludingLineBreak.Position)
                {
                    end = line.EndIncludingLineBreak.Position;
                }
            }
            else
            {
                if (end > line.End.Position)
                {
                    end = line.End.Position;
                }
            }

            if (start > end)
            {
                return(new TextLineFragment(line, start, 0, options));
            }

            var count = end - start;

            return(new TextLineFragment(line, start, count, options));
        }