public static String unexpandLine ( CharSequence self , int tabStop ) { StringBuilder builder = new StringBuilder ( self . toString ( ) ) ; int index = 0 ; while ( index + tabStop < builder . length ( ) ) { // cut original string in tabstop-length pieces String piece = builder . substring ( index , index + tabStop ) ; // count trailing whitespace characters int count = 0 ; while ( ( count < tabStop ) && ( Character . isWhitespace ( piece . charAt ( tabStop - ( count + 1 ) ) ) ) ) count ++ ; // replace if whitespace was found if ( count > 0 ) { piece = piece . substring ( 0 , tabStop - count ) + ' ' ; builder . replace ( index , index + tabStop , piece ) ; index = index + tabStop - ( count - 1 ) ; } else index = index + tabStop ; } return builder . toString ( ) ; }
Replaces sequences of whitespaces with tabs within a line .