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 trimmedTriviaText      = triviaText.TrimEnd(s_trimChars);
            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));
        }
Beispiel #2
0
            private string CreateString(TriviaDataWithList triviaData, CancellationToken cancellationToken)
            {
                // create string from given trivia data
                var sb = StringBuilderPool.Allocate();

                foreach (var trivia in triviaData.GetTriviaList(cancellationToken))
                {
                    sb.Append(trivia.ToFullString());
                }

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

                    builder.AppendIndentationString(this.Spaces, this.OptionSet.GetOption(FormattingOptions.UseTabs, this.Language), this.OptionSet.GetOption(FormattingOptions.TabSize, this.Language));
                    return(StringBuilderPool.ReturnAndFree(builder));
                }

                // space case. always use space
                return(new string(' ', this.Spaces));
            }
        public static string ReindentStartOfXmlDocumentationComment(
            this string triviaText,
            bool forceIndentation,
            int indentation,
            int indentationDelta,
            bool useTab,
            int tabSize,
            string newLine)
        {
            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(s_trimChars));
            if (0 < lines.Length - 1)
            {
                builder.Append(newLine);
            }

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

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

            return(StringBuilderPool.ReturnAndFree(builder));
        }