TStringUtil extends StringUtils { public static String fillTabWithSpace(String str) { if (str == null) { return null; } str = str.trim(); int sz = str.length(); StringBuilder buffer = new StringBuilder(sz); int index = 0, index0 = -1, index1 = -1; for (int i = 0; i < sz; i++) { char c = str.charAt(i); if (!Character.isWhitespace(c)) { if (index0 != -1) { if (index0 != index1 || str.charAt(i - 1) != ' ') { buffer.append(str.substring(index, index0)).append(" "); index = index1 + 1; } } index0 = index1 = -1; } else { if (index0 == -1) { index0 = index1 = i; } else { index1 = i; } } } buffer.append(str.substring(index)); return buffer.toString(); }  static String getBetween(String sql, String start, String end); static String removeBetween(String sql, String start, String end); static String[] twoPartSplit(String str, String splitor); static List<String> recursiveSplit(String str, String splitor); static String fillTabWithSpace(String str); static boolean startsWithIgnoreCaseAndWs(String searchIn, String searchFor); static boolean startsWithIgnoreCaseAndWs(String searchIn, String searchFor, int beginPos); static boolean startsWithIgnoreCase(String searchIn, int startAt, String searchFor); static String stripComments(String src, String stringOpens, String stringCloses, boolean slashStarComments,
                                       boolean slashSlashComments, boolean hashComments, boolean dashDashComments); static String removeBetweenWithSplitor(String sql, String start, String end); static String removeBetweenWithSplitorNotExistNull(String sql, String start, String end); static boolean isTableFatherAndSon(String fatherTable, String sonTable);  }
@Test public void testFillTabWithSpace() { String sql = " select sum(rate) from feed_receive_0117 t where RATED_UID=? and RATER_UID=? and suspended=0 and validscore=1 and rater_type=? and trade_closingdate>=? and trade_closingdate<? and id<>? and (IFNULL(IMPORT_FROM, 0)&8) = 0 #@#mysql_feel_01#@#EXECUTE_A_SQL_TIMEOUT#@#1#@#484#@#484#@#484"; String assertSql = "select sum(rate) from feed_receive_0117 t where RATED_UID=? and RATER_UID=? and suspended=0 and validscore=1 and rater_type=? and trade_closingdate>=? and trade_closingdate<? and id<>? and (IFNULL(IMPORT_FROM, 0)&8) = 0 #@#mysql_feel_01#@#EXECUTE_A_SQL_TIMEOUT#@#1#@#484#@#484#@#484"; String acutulSql = null; acutulSql = TStringUtil.fillTabWithSpace(sql); Assert.assertEquals(assertSql, acutulSql); }