code: 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) + '\t';
                  builder.replace(index, index + tabStop, piece);
                  index = index + tabStop - (count - 1);
              } else
                  index = index + tabStop;
          }
          return builder.toString();
      }
docs: Replaces sequences of whitespaces with tabs within a line.
  
  @param self A line to unexpand
  @param tabStop The number of spaces a tab represents
  @return an unexpanded String
  @since 1.8.2