public static string ReindentStartOfXmlDocumentationComment(
            this string triviaText,
            bool forceIndentation,
            int indentation,
            int indentationDelta,
            bool useTab,
            int tabSize)
        {
            var builder = StringBuilderPool.Allocate();

            // split xml doc comments into lines
            var lines = triviaText.Split('\n');

            Contract.ThrowIfFalse(lines.Length > 0);

            // add first line and append new line iff it is not a single line xml doc comment
            builder.Append(lines[0].Trim(trimChars));
            if (0 < lines.Length - 1)
            {
                builder.AppendLine();
            }

            // add rest of xml doc comments
            for (int i = 1; i < lines.Length; i++)
            {
                var line = lines[i].TrimEnd(trimChars);
                var nonWhitespaceCharIndex = GetFirstNonWhitespaceIndexInString(line);
                if (nonWhitespaceCharIndex >= 0)
                {
                    var newIndentation       = GetNewIndentationForComments(line, nonWhitespaceCharIndex, forceIndentation, indentation, indentationDelta, tabSize);
                    var newIndentationString = newIndentation.CreateIndentationString(useTab, tabSize);

                    builder.Append(newIndentationString);
                    builder.Append(line, nonWhitespaceCharIndex, line.Length - nonWhitespaceCharIndex);
                }

                if (i < lines.Length - 1)
                {
                    builder.AppendLine();
                }
            }

            return(StringBuilderPool.ReturnAndFree(builder));
        }
Esempio n. 2
0
        public static string AdjustIndentForXmlDocExteriorTrivia(
            this string triviaText,
            bool forceIndentation,
            int indentation,
            int indentationDelta,
            bool useTab,
            int tabSize
            )
        {
            var isEmptyString = false;
            var builder       = StringBuilderPool.Allocate();

            var nonWhitespaceCharIndex = GetFirstNonWhitespaceIndexInString(triviaText);

            if (nonWhitespaceCharIndex == -1)
            {
                isEmptyString          = true;
                nonWhitespaceCharIndex = triviaText.Length;
            }

            var newIndentation = GetNewIndentationForComments(
                triviaText,
                nonWhitespaceCharIndex,
                forceIndentation,
                indentation,
                indentationDelta,
                tabSize
                );

            builder.AppendIndentationString(newIndentation, useTab, tabSize);
            if (!isEmptyString)
            {
                builder.Append(
                    triviaText,
                    nonWhitespaceCharIndex,
                    triviaText.Length - nonWhitespaceCharIndex
                    );
            }

            return(StringBuilderPool.ReturnAndFree(builder));
        }
Esempio n. 3
0
            private string CreateString(string newLine)
            {
                if (this.SecondTokenIsFirstTokenOnLine)
                {
                    var builder = StringBuilderPool.Allocate();
                    for (var i = 0; i < this.LineBreaks; i++)
                    {
                        builder.Append(newLine);
                    }

                    builder.AppendIndentationString(
                        this.Spaces,
                        this.Options.GetOption(FormattingOptions2.UseTabs),
                        this.Options.GetOption(FormattingOptions2.TabSize)
                        );
                    return(StringBuilderPool.ReturnAndFree(builder));
                }

                // space case. always use space
                return(new string(' ', this.Spaces));
            }