Exemplo n.º 1
0
        /// <summary>
        /// Given text string (typically content of a text buffer)
        /// calculates size of indentation (length of the leading
        /// whitespace in the line) in spaces.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="tabSize"></param>
        /// <returns></returns>
        public static int TextIndentInSpaces(string text, int tabSize)
        {
            int spaces = 0;
            int indent = 0;

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text[i];

                if (!Char.IsWhiteSpace(ch))
                {
                    break;
                }

                if (ch.IsLineBreak())
                {
                    break;
                }

                indent += IndentBuilder.GetWhiteSpaceCharLength(ch, spaces, tabSize);

                if (ch == ' ')
                {
                    spaces++;
                }
            }

            return(indent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates length of text in spaces, converting tabs to spaces using specified tab size.
        /// </summary>
        public static int TextLengthInSpaces(string text, int tabSize)
        {
            var length = 0;
            var spaces = 0;

            for (var i = 0; i < text.Length; i++)
            {
                var ch = text[i];

                if (ch.IsLineBreak())
                {
                    break;
                }

                length += IndentBuilder.GetWhiteSpaceCharLength(ch, spaces, tabSize);

                if (ch == ' ')
                {
                    spaces++;
                }
            }

            return(length);
        }
Exemplo n.º 3
0
 public TextBuilder(IndentBuilder indentBuilder)
 {
     _indentBuilder = indentBuilder;
 }
Exemplo n.º 4
0
        public static int InnerIndentSizeFromLine(ITextSnapshotLine line, RFormatOptions options) {
            string lineText = line.GetText();
            string leadingWhitespace = lineText.Substring(0, lineText.Length - lineText.TrimStart().Length);
            IndentBuilder indentbuilder = new IndentBuilder(options.IndentType, options.IndentSize, options.TabSize);

            return IndentBuilder.TextIndentInSpaces(leadingWhitespace + indentbuilder.SingleIndentString, options.TabSize);
        }
Exemplo n.º 5
0
 public RFormatter(RFormatOptions options) {
     _options = options;
     _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize);
     _tb = new TextBuilder(_indentBuilder);
     _formattingScopes.Push(new FormattingScope(_indentBuilder));
 }
Exemplo n.º 6
0
 public RFormatter(RFormatOptions options) {
     _options = options;
     _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize);
     _tb = new TextBuilder(_indentBuilder);
 }
Exemplo n.º 7
0
 public FormattingScope(IndentBuilder indentBuilder) {
     _indentBuilder = indentBuilder;
 }
Exemplo n.º 8
0
 public TextBuilder(IndentBuilder indentBuilder) {
     _indentBuilder = indentBuilder;
 }
Exemplo n.º 9
0
 public void CloseIndentLevel() => IndentBuilder.CloseIndentLevel();
Exemplo n.º 10
0
 public void NewIndentLevel() => IndentBuilder.NewIndentLevel();