/// <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);
 }
 /// <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));
 }
    private string GetMarker(ITextSnapshotLine line, TextLineFragment fragment, SnapshotPoint point) {
      string[] markers = {
        "for(",
      };

      return markers
        .Where(marker => fragment.GetText(point - line.Start, marker.Length) == marker)
        .FirstOrDefault();
    }
    private string GetMarker(ITextSnapshotLine line, TextLineFragment fragment, SnapshotPoint point) {
      string[] markers = {
        "else",
        "else if",
      };

      var match = markers
        .Where(marker => fragment.GetText(point - line.Start, marker.Length) == marker)
        .FirstOrDefault();
      if (match != null) {
        // If last character of line is not "{", we are good
        var end = line.GetFragment(line.End.Position - 1, line.End.Position, TextLineFragment.Options.Default);
        if (end.GetText() != "{")
          return null;
      }
      return match;
    }
    /// <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);
    }