/// <summary>
        /// Retrieves a line of text from the document.
        /// </summary>
        /// <param name="Index">The index of the line to retrieve.</param>
        /// <param name="bIncludeEOL">True if the line includes the EOL characters.</param>
        /// <returns>A string containing the text of the specified line.</returns>
        public string GetLine(int Index, bool bIncludeEOL)
        {
            DocumentLine Line = mLines[Index];

            if (!bIncludeEOL && Line.Length >= 2 && Line[Line.Length - 1] == '\n' && Line[Line.Length - 2] == '\r')
            {
                return(Line.ToString(0, Line.Length - 2));
            }

            return(Line.ToString());
        }
        /// <summary>
        /// Searches for a string in the reverse direction of <see cref="FindForward"/>.
        /// </summary>
        /// <param name="Txt">The text to search for.</param>
        /// <param name="StartLoc">The starting location of the search.</param>
        /// <param name="EndLoc">The ending location of the search.</param>
        /// <param name="Flags">Flags controlling how the searching is conducted.</param>
        /// <param name="Result">Receives the results of the search.</param>
        /// <returns>True if a match was found.</returns>
        private bool FindReverse(string Txt, ref TextLocation StartLoc, ref TextLocation EndLoc, RichTextBoxFinds Flags, out FindResult Result)
        {
            bool             bFound = false;
            bool             bMatchWord;
            bool             bIsWord;
            StringComparison ComparisonFlags;

            SetupFindState(Txt, ref StartLoc, ref EndLoc, Flags, out Result, out bIsWord, out ComparisonFlags, out bMatchWord);

            for (int CurLineIndex = StartLoc.Line; CurLineIndex >= EndLoc.Line && !bFound; --CurLineIndex)
            {
                if (GetLineLength(CurLineIndex) == 0)
                {
                    continue;
                }

                DocumentLine CurLineBldr = mLines[CurLineIndex];
                string       LineTxt;
                int          ColumnIndex = 0;

                if (CurLineIndex == StartLoc.Line && StartLoc.Column < GetLineLength(CurLineIndex))
                {
                    LineTxt = CurLineBldr.ToString(0, StartLoc.Column);
                }
                else if (CurLineIndex == EndLoc.Line && EndLoc.Column > 0)
                {
                    LineTxt     = CurLineBldr.ToString(EndLoc.Column, CurLineBldr.Length - EndLoc.Column);
                    ColumnIndex = EndLoc.Column;
                }
                else
                {
                    LineTxt = CurLineBldr.ToString();
                }

                int Index = LineTxt.LastIndexOf(Txt, ComparisonFlags);

                if (Index != -1)
                {
                    ColumnIndex += Index;
                    CheckForWholeWord(Txt, ref Result, bMatchWord, ref bFound, bIsWord, CurLineIndex, CurLineBldr, ColumnIndex, Index);
                }
            }

            return(bFound);
        }
        /// <summary>
        /// Creates a new document by filtering out the lines of the current document using the supplied filter function.
        /// </summary>
        /// <param name="Filter">The function that will filter the lines out of the current document.</param>
        /// <param name="Data">User supplied data that may control filtering.</param>
        /// <returns>A new document containing filtered lines from the current document.</returns>
        public OutputWindowDocument CreateFilteredDocument(OutputWindowDocumentFilterDelegate Filter, object Data)
        {
            if (Filter == null)
            {
                throw new ArgumentNullException("Filter");
            }

            OutputWindowDocument NewDoc = new OutputWindowDocument();

            NewDoc.mLines.Capacity = mLines.Capacity;
            DocumentLine LastLine = null;

            foreach (DocumentLine CurLine in mLines)
            {
                if (!Filter(new ReadOnlyDocumentLine(CurLine), Data))
                {
                    DocumentLine NewLine = (DocumentLine)CurLine.Clone();
                    NewDoc.mLines.Add(NewLine);

                    int LineLength = GetLineLength(NewLine);

                    if (LineLength > NewDoc.mLongestLineLength)
                    {
                        NewDoc.mLongestLineLength = LineLength;
                    }

                    LastLine = NewLine;
                }
            }

            // If the last line is a full line we need to append an empty line because the empty line has been filtered out
            if (LastLine != null && LastLine.ToString().EndsWith(Environment.NewLine))
            {
                NewDoc.mLines.Add(new DocumentLine());
            }

            return(NewDoc);
        }
 /// <summary>
 /// Returns the text associated with the line.
 /// </summary>
 /// <returns>The text associated with the line.</returns>
 public override string ToString()
 {
     return(mDocLine.ToString());
 }