/// <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); }
/// <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); }
public TextBuilder(IndentBuilder indentBuilder) { _indentBuilder = indentBuilder; }
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); }
public RFormatter(RFormatOptions options) { _options = options; _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize); _tb = new TextBuilder(_indentBuilder); _formattingScopes.Push(new FormattingScope(_indentBuilder)); }
public RFormatter(RFormatOptions options) { _options = options; _indentBuilder = new IndentBuilder(_options.IndentType, _options.IndentSize, _options.TabSize); _tb = new TextBuilder(_indentBuilder); }
public FormattingScope(IndentBuilder indentBuilder) { _indentBuilder = indentBuilder; }
public void CloseIndentLevel() => IndentBuilder.CloseIndentLevel();
public void NewIndentLevel() => IndentBuilder.NewIndentLevel();