public String replaceTabs ( Configuration configuration , String text ) { if ( ! text . contains ( "\t" ) ) return text ; final int tabLength = configuration . sourcetab ; final String whitespace = configuration . tabSpaces ; final int textLength = text . length ( ) ; StringBuilder result = new StringBuilder ( textLength ) ; int pos = 0 ; int lineLength = 0 ; for ( int i = 0 ; i < textLength ; i ++ ) { char ch = text . charAt ( i ) ; switch ( ch ) { case ' ' : case ' ' : lineLength = 0 ; break ; case ' ' : result . append ( text , pos , i ) ; int spaceCount = tabLength - lineLength % tabLength ; result . append ( whitespace , 0 , spaceCount ) ; lineLength += spaceCount ; pos = i + 1 ; break ; default : lineLength ++ ; } } result . append ( text , pos , textLength ) ; return result . toString ( ) ; }
Replace all tabs in a string with the appropriate number of spaces . The string may be a multi - line string .