public static GetWhiteSpaceCharLength ( char character, int spacesSoFar, int tabSize ) : int | ||
character | char | |
spacesSoFar | int | |
tabSize | int | |
Résultat | int |
public static int GetWhiteSpaceCharLength(char character, int spacesSoFar, int tabSize) {
Debug.Assert(spacesSoFar >= 0, "number of spaces must be bigger than zero");
if (character == '\t') {
return tabSize - spacesSoFar % tabSize;
}
if (character.IsLineBreak()) {
Debug.Fail("We don't expect any new lines here");
return 1;
}
if (Char.IsWhiteSpace(character)) {
return 1;
}
return 1;
}
/// <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); }