GetWhiteSpaceCharLength() public static method

Returns a conversion of tabs or space to space count. You can't simply get the tab size from options, because spaces before tabs blend in with the tabs, while spaces after the tabs add up.
public static GetWhiteSpaceCharLength ( char character, int spacesSoFar, int tabSize ) : int
character char
spacesSoFar int
tabSize int
return int
コード例 #1
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);
        }