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 (var 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));
            }
Exemplo n.º 3
0
        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);
                    var newIndentationString = newIndentation.CreateIndentationString(useTab, tabSize);

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

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

            return(StringBuilderPool.ReturnAndFree(builder));
        }
Exemplo n.º 4
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));
        }