コード例 #1
0
        /* Function: FindIncludeInOutput
         * Extracts and returns any comment content marked "include in output".  All comment symbols and extra indents
         * will be removed.  Returns null if the comment doesn't have any.
         */
        protected string FindIncludeInOutput(PossibleDocumentationComment comment)
        {
            Comments.LineFinder.MarkTextBoxes(comment);

            LineIterator iterator = comment.Start;


            // Find the "include in output" header if it exists

            while (iterator < comment.End &&
                   iterator.Match(IncludeInOutputRegex, LineBoundsMode.CommentContent).Success == false)
            {
                iterator.Next();
            }

            if (iterator >= comment.End)
            {
                return(null);
            }


            // Find the bounds of the content excluding whitespace and the shared indent level

            iterator.Next();

            while (iterator < comment.End && iterator.IsEmpty(LineBoundsMode.CommentContent))
            {
                iterator.Next();
            }

            LineIterator start        = iterator;
            LineIterator end          = iterator;
            int          commonIndent = 9999;

            while (iterator < comment.End)
            {
                if (iterator.IsEmpty(LineBoundsMode.CommentContent))
                {
                    iterator.Next();
                }
                else
                {
                    if (iterator.Indent(LineBoundsMode.CommentContent) < commonIndent)
                    {
                        commonIndent = iterator.Indent(LineBoundsMode.CommentContent);
                    }

                    iterator.Next();
                    end = iterator;
                }
            }


            // Build and return the comment content

            if (start >= end)
            {
                return(null);
            }

            StringBuilder output = new StringBuilder();

            do
            {
                int indentDifference = start.Indent(LineBoundsMode.CommentContent) - commonIndent;

                if (indentDifference > 0)
                {
                    output.Append(' ', indentDifference);
                }

                start.AppendTo(output, LineBoundsMode.CommentContent);
                output.AppendLine();

                start.Next();
            }while (start < end);

            return(output.ToString());
        }