// ============================================================================ // // Copyright (C) 2006-2015 Talend Inc. - www.talend.com // // This source code is available under agreement available at // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt // // You should have received a copy of the agreement // along with this program; if not, write to Talend SA // 9 rue Pages 92150 Suresnes, France // // ============================================================================ package routines.system; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringUtils { public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final String EMPTY = ""; /** * replace the method : String.split(String regex) * @param str * @param separatorChars * @return */ public static String[] splitNotRegex(String str,String separatorChars) { if (str == null) { return null; } int len = str.length(); if (len == 0) { return EMPTY_STRING_ARRAY; } int separatorLength = separatorChars.length(); ArrayList substrings = new ArrayList(); int beg = 0; int end = 0; while (end < len) { end = str.indexOf(separatorChars, beg); if (end > -1) { if (end > beg) { substrings.add(str.substring(beg, end)); beg = end + separatorLength; } else { substrings.add(EMPTY); beg = end + separatorLength; } } else { substrings.add(str.substring(beg)); end = len; } } int resultSize = substrings.size(); while (resultSize > 0 && substrings.get(resultSize-1).equals("")) { resultSize--; } String[] result = new String[resultSize]; return substrings.subList(0, resultSize).toArray(result); } /** * split SQL columns like that : * from : * id, name, CONCAT(name,UPPER(address)), CONCAT(age,name) * to * [id] [name] [CONCAT(name,UPPER(address))] [CONCAT(age,name)] */ public static String[] splitSQLColumns(String sql) { List result = new ArrayList(); int blockCount = 0; int start = 0; for(int i=0;i