一、前言
参考hutool的hutool-all包的cn.hutool.core.util.StrUtil字符串工具类,对字符串非空判断、是否包含、头尾字符处理、前后缀删除追加、拆分合并及替换包装等处理。
二、代码说明
package cn.hutool.core.util;@b@@b@import cn.hutool.core.comparator.VersionComparator;@b@import cn.hutool.core.convert.Convert;@b@import cn.hutool.core.lang.Assert;@b@import cn.hutool.core.lang.Func1;@b@import cn.hutool.core.lang.Matcher;@b@import cn.hutool.core.text.StrBuilder;@b@import cn.hutool.core.text.StrFormatter;@b@import cn.hutool.core.text.StrSpliter;@b@import cn.hutool.core.text.TextSimilarity;@b@import java.io.StringReader;@b@import java.io.StringWriter;@b@import java.nio.ByteBuffer;@b@import java.nio.charset.Charset;@b@import java.text.MessageFormat;@b@import java.util.ArrayList;@b@import java.util.HashSet;@b@import java.util.Iterator;@b@import java.util.List;@b@import java.util.Map;@b@import java.util.Set;@b@import java.util.Map.Entry;@b@import java.util.regex.Pattern;@b@@b@public class StrUtil {@b@ public static final int INDEX_NOT_FOUND = -1;@b@ public static final char C_SPACE = ' ';@b@ public static final char C_TAB = '\t';@b@ public static final char C_DOT = '.';@b@ public static final char C_SLASH = '/';@b@ public static final char C_BACKSLASH = '\\';@b@ public static final char C_CR = '\r';@b@ public static final char C_LF = '\n';@b@ public static final char C_UNDERLINE = '_';@b@ public static final char C_COMMA = ',';@b@ public static final char C_DELIM_START = '{';@b@ public static final char C_DELIM_END = '}';@b@ public static final char C_BRACKET_START = '[';@b@ public static final char C_BRACKET_END = ']';@b@ public static final char C_COLON = ':';@b@ public static final String SPACE = " ";@b@ public static final String TAB = "\t";@b@ public static final String DOT = ".";@b@ public static final String DOUBLE_DOT = "..";@b@ public static final String SLASH = "/";@b@ public static final String BACKSLASH = "\\";@b@ public static final String EMPTY = "";@b@ public static final String CR = "\r";@b@ public static final String LF = "\n";@b@ public static final String CRLF = "\r\n";@b@ public static final String UNDERLINE = "_";@b@ public static final String DASHED = "-";@b@ public static final String COMMA = ",";@b@ public static final String DELIM_START = "{";@b@ public static final String DELIM_END = "}";@b@ public static final String BRACKET_START = "[";@b@ public static final String BRACKET_END = "]";@b@ public static final String COLON = ":";@b@ public static final String HTML_NBSP = " ";@b@ public static final String HTML_AMP = "&";@b@ public static final String HTML_QUOTE = """;@b@ public static final String HTML_APOS = "'";@b@ public static final String HTML_LT = "<";@b@ public static final String HTML_GT = ">";@b@ public static final String EMPTY_JSON = "{}";@b@@b@ public StrUtil() {@b@ }@b@@b@ public static boolean isBlank(CharSequence str) {@b@ int length;@b@ if (str != null && (length = str.length()) != 0) {@b@ for(int i = 0; i < length; ++i) {@b@ if (!CharUtil.isBlankChar(str.charAt(i))) {@b@ return false;@b@ }@b@ }@b@@b@ return true;@b@ } else {@b@ return true;@b@ }@b@ }@b@@b@ public static boolean isBlankIfStr(Object obj) {@b@ if (null == obj) {@b@ return true;@b@ } else {@b@ return obj instanceof CharSequence ? isBlank((CharSequence)obj) : false;@b@ }@b@ }@b@@b@ public static boolean isNotBlank(CharSequence str) {@b@ return !isBlank(str);@b@ }@b@@b@ public static boolean hasBlank(CharSequence... strs) {@b@ if (ArrayUtil.isEmpty(strs)) {@b@ return true;@b@ } else {@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ if (isBlank(str)) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ }@b@ }@b@@b@ public static boolean isAllBlank(CharSequence... strs) {@b@ if (ArrayUtil.isEmpty(strs)) {@b@ return true;@b@ } else {@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ if (isNotBlank(str)) {@b@ return false;@b@ }@b@ }@b@@b@ return true;@b@ }@b@ }@b@@b@ public static boolean isEmpty(CharSequence str) {@b@ return str == null || str.length() == 0;@b@ }@b@@b@ public static boolean isEmptyIfStr(Object obj) {@b@ if (null == obj) {@b@ return true;@b@ } else if (obj instanceof CharSequence) {@b@ return 0 == ((CharSequence)obj).length();@b@ } else {@b@ return false;@b@ }@b@ }@b@@b@ public static boolean isNotEmpty(CharSequence str) {@b@ return !isEmpty(str);@b@ }@b@@b@ public static String nullToEmpty(CharSequence str) {@b@ return nullToDefault(str, "");@b@ }@b@@b@ public static String nullToDefault(CharSequence str, String defaultStr) {@b@ return str == null ? defaultStr : str.toString();@b@ }@b@@b@ public static String emptyToDefault(CharSequence str, String defaultStr) {@b@ return isEmpty(str) ? defaultStr : str.toString();@b@ }@b@@b@ public static String blankToDefault(CharSequence str, String defaultStr) {@b@ return isBlank(str) ? defaultStr : str.toString();@b@ }@b@@b@ public static String emptyToNull(CharSequence str) {@b@ return isEmpty(str) ? null : str.toString();@b@ }@b@@b@ public static boolean hasEmpty(CharSequence... strs) {@b@ if (ArrayUtil.isEmpty(strs)) {@b@ return true;@b@ } else {@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ if (isEmpty(str)) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ }@b@ }@b@@b@ public static boolean isAllEmpty(CharSequence... strs) {@b@ if (ArrayUtil.isEmpty(strs)) {@b@ return true;@b@ } else {@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ if (isNotEmpty(str)) {@b@ return false;@b@ }@b@ }@b@@b@ return true;@b@ }@b@ }@b@@b@ public static boolean isNullOrUndefined(CharSequence str) {@b@ return null == str ? true : isNullOrUndefinedStr(str);@b@ }@b@@b@ public static boolean isEmptyOrUndefined(CharSequence str) {@b@ return isEmpty(str) ? true : isNullOrUndefinedStr(str);@b@ }@b@@b@ public static boolean isBlankOrUndefined(CharSequence str) {@b@ return isBlank(str) ? true : isNullOrUndefinedStr(str);@b@ }@b@@b@ private static boolean isNullOrUndefinedStr(CharSequence str) {@b@ String strString = str.toString().trim();@b@ return "null".equals(strString) || "undefined".equals(strString);@b@ }@b@@b@ public static String trim(CharSequence str) {@b@ return null == str ? null : trim(str, 0);@b@ }@b@@b@ public static void trim(String[] strs) {@b@ if (null != strs) {@b@ for(int i = 0; i < strs.length; ++i) {@b@ String str = strs[i];@b@ if (null != str) {@b@ strs[i] = str.trim();@b@ }@b@ }@b@@b@ }@b@ }@b@@b@ public static String trimToEmpty(CharSequence str) {@b@ return str == null ? "" : trim(str);@b@ }@b@@b@ public static String trimToNull(CharSequence str) {@b@ String trimStr = trim(str);@b@ return "".equals(trimStr) ? null : trimStr;@b@ }@b@@b@ public static String trimStart(CharSequence str) {@b@ return trim(str, -1);@b@ }@b@@b@ public static String trimEnd(CharSequence str) {@b@ return trim(str, 1);@b@ }@b@@b@ public static String trim(CharSequence str, int mode) {@b@ if (str == null) {@b@ return null;@b@ } else {@b@ int length = str.length();@b@ int start = 0;@b@ int end = length;@b@ if (mode <= 0) {@b@ while(start < end && CharUtil.isBlankChar(str.charAt(start))) {@b@ ++start;@b@ }@b@ }@b@@b@ if (mode >= 0) {@b@ while(start < end && CharUtil.isBlankChar(str.charAt(end - 1))) {@b@ --end;@b@ }@b@ }@b@@b@ return start <= 0 && end >= length ? str.toString() : str.toString().substring(start, end);@b@ }@b@ }@b@@b@ public static boolean startWith(CharSequence str, char c) {@b@ return c == str.charAt(0);@b@ }@b@@b@ public static boolean startWith(CharSequence str, CharSequence prefix, boolean isIgnoreCase) {@b@ if (null != str && null != prefix) {@b@ return isIgnoreCase ? str.toString().toLowerCase().startsWith(prefix.toString().toLowerCase()) : str.toString().startsWith(prefix.toString());@b@ } else {@b@ return null == str && null == prefix;@b@ }@b@ }@b@@b@ public static boolean startWith(CharSequence str, CharSequence prefix) {@b@ return startWith(str, prefix, false);@b@ }@b@@b@ public static boolean startWithIgnoreCase(CharSequence str, CharSequence prefix) {@b@ return startWith(str, prefix, true);@b@ }@b@@b@ public static boolean startWithAny(CharSequence str, CharSequence... prefixes) {@b@ if (!isEmpty(str) && !ArrayUtil.isEmpty(prefixes)) {@b@ CharSequence[] arr$ = prefixes;@b@ int len$ = prefixes.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence suffix = arr$[i$];@b@ if (startWith(str, suffix, false)) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ } else {@b@ return false;@b@ }@b@ }@b@@b@ public static boolean endWith(CharSequence str, char c) {@b@ return c == str.charAt(str.length() - 1);@b@ }@b@@b@ public static boolean endWith(CharSequence str, CharSequence suffix, boolean isIgnoreCase) {@b@ if (null != str && null != suffix) {@b@ return isIgnoreCase ? str.toString().toLowerCase().endsWith(suffix.toString().toLowerCase()) : str.toString().endsWith(suffix.toString());@b@ } else {@b@ return null == str && null == suffix;@b@ }@b@ }@b@@b@ public static boolean endWith(CharSequence str, CharSequence suffix) {@b@ return endWith(str, suffix, false);@b@ }@b@@b@ public static boolean endWithIgnoreCase(CharSequence str, CharSequence suffix) {@b@ return endWith(str, suffix, true);@b@ }@b@@b@ public static boolean endWithAny(CharSequence str, CharSequence... suffixes) {@b@ if (!isEmpty(str) && !ArrayUtil.isEmpty(suffixes)) {@b@ CharSequence[] arr$ = suffixes;@b@ int len$ = suffixes.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence suffix = arr$[i$];@b@ if (endWith(str, suffix, false)) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ } else {@b@ return false;@b@ }@b@ }@b@@b@ public static boolean contains(CharSequence str, char searchChar) {@b@ return indexOf(str, searchChar) > -1;@b@ }@b@@b@ public static boolean containsAny(CharSequence str, CharSequence... testStrs) {@b@ return null != getContainsStr(str, testStrs);@b@ }@b@@b@ public static boolean containsAny(CharSequence str, char... testChars) {@b@ if (!isEmpty(str)) {@b@ int len = str.length();@b@@b@ for(int i = 0; i < len; ++i) {@b@ if (ArrayUtil.contains(testChars, str.charAt(i))) {@b@ return true;@b@ }@b@ }@b@ }@b@@b@ return false;@b@ }@b@@b@ public static boolean containsBlank(CharSequence str) {@b@ if (null == str) {@b@ return false;@b@ } else {@b@ int length = str.length();@b@ if (0 == length) {@b@ return false;@b@ } else {@b@ for(int i = 0; i < length; ++i) {@b@ if (CharUtil.isBlankChar(str.charAt(i))) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ }@b@ }@b@ }@b@@b@ public static String getContainsStr(CharSequence str, CharSequence... testStrs) {@b@ if (!isEmpty(str) && !ArrayUtil.isEmpty(testStrs)) {@b@ CharSequence[] arr$ = testStrs;@b@ int len$ = testStrs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence checkStr = arr$[i$];@b@ if (str.toString().contains(checkStr)) {@b@ return checkStr.toString();@b@ }@b@ }@b@@b@ return null;@b@ } else {@b@ return null;@b@ }@b@ }@b@@b@ public static boolean containsIgnoreCase(CharSequence str, CharSequence testStr) {@b@ if (null == str) {@b@ return null == testStr;@b@ } else {@b@ return str.toString().toLowerCase().contains(testStr.toString().toLowerCase());@b@ }@b@ }@b@@b@ public static boolean containsAnyIgnoreCase(CharSequence str, CharSequence... testStrs) {@b@ return null != getContainsStrIgnoreCase(str, testStrs);@b@ }@b@@b@ public static String getContainsStrIgnoreCase(CharSequence str, CharSequence... testStrs) {@b@ if (!isEmpty(str) && !ArrayUtil.isEmpty(testStrs)) {@b@ CharSequence[] arr$ = testStrs;@b@ int len$ = testStrs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence testStr = arr$[i$];@b@ if (containsIgnoreCase(str, testStr)) {@b@ return testStr.toString();@b@ }@b@ }@b@@b@ return null;@b@ } else {@b@ return null;@b@ }@b@ }@b@@b@ public static String getGeneralField(CharSequence getOrSetMethodName) {@b@ String getOrSetMethodNameStr = getOrSetMethodName.toString();@b@ return !getOrSetMethodNameStr.startsWith("get") && !getOrSetMethodNameStr.startsWith("set") ? null : removePreAndLowerFirst(getOrSetMethodName, 3);@b@ }@b@@b@ public static String genSetter(CharSequence fieldName) {@b@ return upperFirstAndAddPre(fieldName, "set");@b@ }@b@@b@ public static String genGetter(CharSequence fieldName) {@b@ return upperFirstAndAddPre(fieldName, "get");@b@ }@b@@b@ public static String removeAll(CharSequence str, CharSequence strToRemove) {@b@ return isEmpty(str) ? str(str) : str.toString().replace(strToRemove, "");@b@ }@b@@b@ public static String removeAll(CharSequence str, char... chars) {@b@ if (null != str && !ArrayUtil.isEmpty(chars)) {@b@ int len = str.length();@b@ if (0 == len) {@b@ return str(str);@b@ } else {@b@ StringBuilder builder = builder(len);@b@@b@ for(int i = 0; i < len; ++i) {@b@ char c = str.charAt(i);@b@ if (!ArrayUtil.contains(chars, c)) {@b@ builder.append(c);@b@ }@b@ }@b@@b@ return builder.toString();@b@ }@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String removeAllLineBreaks(CharSequence str) {@b@ return removeAll(str, '\r', '\n');@b@ }@b@@b@ public static String removePreAndLowerFirst(CharSequence str, int preLength) {@b@ if (str == null) {@b@ return null;@b@ } else if (str.length() > preLength) {@b@ char first = Character.toLowerCase(str.charAt(preLength));@b@ return str.length() > preLength + 1 ? first + str.toString().substring(preLength + 1) : String.valueOf(first);@b@ } else {@b@ return str.toString();@b@ }@b@ }@b@@b@ public static String removePreAndLowerFirst(CharSequence str, CharSequence prefix) {@b@ return lowerFirst(removePrefix(str, prefix));@b@ }@b@@b@ public static String upperFirstAndAddPre(CharSequence str, String preString) {@b@ return str != null && preString != null ? preString + upperFirst(str) : null;@b@ }@b@@b@ public static String upperFirst(CharSequence str) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ if (str.length() > 0) {@b@ char firstChar = str.charAt(0);@b@ if (Character.isLowerCase(firstChar)) {@b@ return Character.toUpperCase(firstChar) + subSuf(str, 1);@b@ }@b@ }@b@@b@ return str.toString();@b@ }@b@ }@b@@b@ public static String lowerFirst(CharSequence str) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ if (str.length() > 0) {@b@ char firstChar = str.charAt(0);@b@ if (Character.isUpperCase(firstChar)) {@b@ return Character.toLowerCase(firstChar) + subSuf(str, 1);@b@ }@b@ }@b@@b@ return str.toString();@b@ }@b@ }@b@@b@ public static String removePrefix(CharSequence str, CharSequence prefix) {@b@ if (!isEmpty(str) && !isEmpty(prefix)) {@b@ String str2 = str.toString();@b@ return str2.startsWith(prefix.toString()) ? subSuf(str2, prefix.length()) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String removePrefixIgnoreCase(CharSequence str, CharSequence prefix) {@b@ if (!isEmpty(str) && !isEmpty(prefix)) {@b@ String str2 = str.toString();@b@ return str2.toLowerCase().startsWith(prefix.toString().toLowerCase()) ? subSuf(str2, prefix.length()) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String removeSuffix(CharSequence str, CharSequence suffix) {@b@ if (!isEmpty(str) && !isEmpty(suffix)) {@b@ String str2 = str.toString();@b@ return str2.endsWith(suffix.toString()) ? subPre(str2, str2.length() - suffix.length()) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String removeSufAndLowerFirst(CharSequence str, CharSequence suffix) {@b@ return lowerFirst(removeSuffix(str, suffix));@b@ }@b@@b@ public static String removeSuffixIgnoreCase(CharSequence str, CharSequence suffix) {@b@ if (!isEmpty(str) && !isEmpty(suffix)) {@b@ String str2 = str.toString();@b@ return str2.toLowerCase().endsWith(suffix.toString().toLowerCase()) ? subPre(str2, str2.length() - suffix.length()) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String strip(CharSequence str, CharSequence prefixOrSuffix) {@b@ return strip(str, prefixOrSuffix, prefixOrSuffix);@b@ }@b@@b@ public static String strip(CharSequence str, CharSequence prefix, CharSequence suffix) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int from = 0;@b@ int to = str.length();@b@ String str2 = str.toString();@b@ if (startWith(str2, prefix)) {@b@ from = prefix.length();@b@ }@b@@b@ if (endWith(str2, suffix)) {@b@ to -= suffix.length();@b@ }@b@@b@ return str2.substring(from, to);@b@ }@b@ }@b@@b@ public static String stripIgnoreCase(CharSequence str, CharSequence prefixOrSuffix) {@b@ return stripIgnoreCase(str, prefixOrSuffix, prefixOrSuffix);@b@ }@b@@b@ public static String stripIgnoreCase(CharSequence str, CharSequence prefix, CharSequence suffix) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int from = 0;@b@ int to = str.length();@b@ String str2 = str.toString();@b@ if (startWithIgnoreCase(str2, prefix)) {@b@ from = prefix.length();@b@ }@b@@b@ if (endWithIgnoreCase(str2, suffix)) {@b@ to -= suffix.length();@b@ }@b@@b@ return str2.substring(from, to);@b@ }@b@ }@b@@b@ public static String addPrefixIfNot(CharSequence str, CharSequence prefix) {@b@ if (!isEmpty(str) && !isEmpty(prefix)) {@b@ String str2 = str.toString();@b@ String prefix2 = prefix.toString();@b@ return !str2.startsWith(prefix2) ? prefix2.concat(str2) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String addSuffixIfNot(CharSequence str, CharSequence suffix) {@b@ if (!isEmpty(str) && !isEmpty(suffix)) {@b@ String str2 = str.toString();@b@ String suffix2 = suffix.toString();@b@ return !str2.endsWith(suffix2) ? str2.concat(suffix2) : str2;@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String cleanBlank(CharSequence str) {@b@ if (str == null) {@b@ return null;@b@ } else {@b@ int len = str.length();@b@ StringBuilder sb = new StringBuilder(len);@b@@b@ for(int i = 0; i < len; ++i) {@b@ char c = str.charAt(i);@b@ if (!CharUtil.isBlankChar(c)) {@b@ sb.append(c);@b@ }@b@ }@b@@b@ return sb.toString();@b@ }@b@ }@b@@b@ public static String[] splitToArray(CharSequence str, char separator) {@b@ return splitToArray(str, separator, 0);@b@ }@b@@b@ public static long[] splitToLong(CharSequence str, char separator) {@b@ return (long[])Convert.convert(long[].class, splitTrim(str, separator));@b@ }@b@@b@ public static long[] splitToLong(CharSequence str, CharSequence separator) {@b@ return (long[])Convert.convert(long[].class, splitTrim(str, separator));@b@ }@b@@b@ public static int[] splitToInt(CharSequence str, char separator) {@b@ return (int[])Convert.convert(int[].class, splitTrim(str, separator));@b@ }@b@@b@ public static int[] splitToInt(CharSequence str, CharSequence separator) {@b@ return (int[])Convert.convert(int[].class, splitTrim(str, separator));@b@ }@b@@b@ public static List<String> split(CharSequence str, char separator) {@b@ return split(str, separator, 0);@b@ }@b@@b@ public static String[] splitToArray(CharSequence str, char separator, int limit) {@b@ return null == str ? new String[0] : StrSpliter.splitToArray(str.toString(), separator, limit, false, false);@b@ }@b@@b@ public static List<String> split(CharSequence str, char separator, int limit) {@b@ return split(str, separator, limit, false, false);@b@ }@b@@b@ public static List<String> splitTrim(CharSequence str, char separator) {@b@ return splitTrim(str, separator, -1);@b@ }@b@@b@ public static List<String> splitTrim(CharSequence str, CharSequence separator) {@b@ return splitTrim(str, separator, -1);@b@ }@b@@b@ public static List<String> splitTrim(CharSequence str, char separator, int limit) {@b@ return split(str, separator, limit, true, true);@b@ }@b@@b@ public static List<String> splitTrim(CharSequence str, CharSequence separator, int limit) {@b@ return split(str, separator, limit, true, true);@b@ }@b@@b@ public static List<String> split(CharSequence str, char separator, boolean isTrim, boolean ignoreEmpty) {@b@ return split(str, separator, 0, isTrim, ignoreEmpty);@b@ }@b@@b@ public static List<String> split(CharSequence str, char separator, int limit, boolean isTrim, boolean ignoreEmpty) {@b@ return (List)(null == str ? new ArrayList(0) : StrSpliter.split(str.toString(), separator, limit, isTrim, ignoreEmpty));@b@ }@b@@b@ public static List<String> split(CharSequence str, CharSequence separator, int limit, boolean isTrim, boolean ignoreEmpty) {@b@ if (null == str) {@b@ return new ArrayList(0);@b@ } else {@b@ String separatorStr = null == separator ? null : separator.toString();@b@ return StrSpliter.split(str.toString(), separatorStr, limit, isTrim, ignoreEmpty);@b@ }@b@ }@b@@b@ public static String[] split(CharSequence str, CharSequence separator) {@b@ if (str == null) {@b@ return new String[0];@b@ } else {@b@ String separatorStr = null == separator ? null : separator.toString();@b@ return StrSpliter.splitToArray(str.toString(), separatorStr, 0, false, false);@b@ }@b@ }@b@@b@ public static String[] split(CharSequence str, int len) {@b@ return null == str ? new String[0] : StrSpliter.splitByLength(str.toString(), len);@b@ }@b@@b@ public static String sub(CharSequence str, int fromIndex, int toIndex) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int len = str.length();@b@ if (fromIndex < 0) {@b@ fromIndex += len;@b@ if (fromIndex < 0) {@b@ fromIndex = 0;@b@ }@b@ } else if (fromIndex > len) {@b@ fromIndex = len;@b@ }@b@@b@ if (toIndex < 0) {@b@ toIndex += len;@b@ if (toIndex < 0) {@b@ toIndex = len;@b@ }@b@ } else if (toIndex > len) {@b@ toIndex = len;@b@ }@b@@b@ if (toIndex < fromIndex) {@b@ int tmp = fromIndex;@b@ fromIndex = toIndex;@b@ toIndex = tmp;@b@ }@b@@b@ return fromIndex == toIndex ? "" : str.toString().substring(fromIndex, toIndex);@b@ }@b@ }@b@@b@ public static String subPreGbk(CharSequence str, int len, CharSequence suffix) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int counterOfDoubleByte = 0;@b@ byte[] b = str.toString().getBytes(CharsetUtil.CHARSET_GBK);@b@ if (b.length <= len) {@b@ return str.toString();@b@ } else {@b@ for(int i = 0; i < len; ++i) {@b@ if (b[i] < 0) {@b@ ++counterOfDoubleByte;@b@ }@b@ }@b@@b@ if (counterOfDoubleByte % 2 != 0) {@b@ ++len;@b@ }@b@@b@ return new String(b, 0, len, CharsetUtil.CHARSET_GBK) + suffix;@b@ }@b@ }@b@ }@b@@b@ public static String maxLength(CharSequence string, int length) {@b@ Assert.isTrue(length > 0);@b@ if (null == string) {@b@ return null;@b@ } else {@b@ return string.length() <= length ? string.toString() : sub(string, 0, length) + "...";@b@ }@b@ }@b@@b@ public static String subPre(CharSequence string, int toIndex) {@b@ return sub(string, 0, toIndex);@b@ }@b@@b@ public static String subSuf(CharSequence string, int fromIndex) {@b@ return isEmpty(string) ? null : sub(string, fromIndex, string.length());@b@ }@b@@b@ public static String subSufByLength(CharSequence string, int length) {@b@ if (isEmpty(string)) {@b@ return null;@b@ } else {@b@ return length <= 0 ? "" : sub(string, -length, string.length());@b@ }@b@ }@b@@b@ public static String subWithLength(String input, int fromIndex, int length) {@b@ return sub(input, fromIndex, fromIndex + length);@b@ }@b@@b@ public static String subBefore(CharSequence string, CharSequence separator, boolean isLastSeparator) {@b@ if (!isEmpty(string) && separator != null) {@b@ String str = string.toString();@b@ String sep = separator.toString();@b@ if (sep.isEmpty()) {@b@ return "";@b@ } else {@b@ int pos = isLastSeparator ? str.lastIndexOf(sep) : str.indexOf(sep);@b@ if (-1 == pos) {@b@ return str;@b@ } else {@b@ return 0 == pos ? "" : str.substring(0, pos);@b@ }@b@ }@b@ } else {@b@ return null == string ? null : string.toString();@b@ }@b@ }@b@@b@ public static String subBefore(CharSequence string, char separator, boolean isLastSeparator) {@b@ if (isEmpty(string)) {@b@ return null == string ? null : string.toString();@b@ } else {@b@ String str = string.toString();@b@ int pos = isLastSeparator ? str.lastIndexOf(separator) : str.indexOf(separator);@b@ if (-1 == pos) {@b@ return str;@b@ } else {@b@ return 0 == pos ? "" : str.substring(0, pos);@b@ }@b@ }@b@ }@b@@b@ public static String subAfter(CharSequence string, CharSequence separator, boolean isLastSeparator) {@b@ if (isEmpty(string)) {@b@ return null == string ? null : string.toString();@b@ } else if (separator == null) {@b@ return "";@b@ } else {@b@ String str = string.toString();@b@ String sep = separator.toString();@b@ int pos = isLastSeparator ? str.lastIndexOf(sep) : str.indexOf(sep);@b@ return -1 != pos && string.length() - 1 != pos ? str.substring(pos + separator.length()) : "";@b@ }@b@ }@b@@b@ public static String subAfter(CharSequence string, char separator, boolean isLastSeparator) {@b@ if (isEmpty(string)) {@b@ return null == string ? null : string.toString();@b@ } else {@b@ String str = string.toString();@b@ int pos = isLastSeparator ? str.lastIndexOf(separator) : str.indexOf(separator);@b@ return -1 == pos ? "" : str.substring(pos + 1);@b@ }@b@ }@b@@b@ public static String subBetween(CharSequence str, CharSequence before, CharSequence after) {@b@ if (str != null && before != null && after != null) {@b@ String str2 = str.toString();@b@ String before2 = before.toString();@b@ String after2 = after.toString();@b@ int start = str2.indexOf(before2);@b@ if (start != -1) {@b@ int end = str2.indexOf(after2, start + before2.length());@b@ if (end != -1) {@b@ return str2.substring(start + before2.length(), end);@b@ }@b@ }@b@@b@ return null;@b@ } else {@b@ return null;@b@ }@b@ }@b@@b@ public static String subBetween(CharSequence str, CharSequence beforeAndAfter) {@b@ return subBetween(str, beforeAndAfter, beforeAndAfter);@b@ }@b@@b@ public static boolean isSurround(CharSequence str, CharSequence prefix, CharSequence suffix) {@b@ if (isBlank(str)) {@b@ return false;@b@ } else if (str.length() < prefix.length() + suffix.length()) {@b@ return false;@b@ } else {@b@ String str2 = str.toString();@b@ return str2.startsWith(prefix.toString()) && str2.endsWith(suffix.toString());@b@ }@b@ }@b@@b@ public static boolean isSurround(CharSequence str, char prefix, char suffix) {@b@ if (isBlank(str)) {@b@ return false;@b@ } else if (str.length() < 2) {@b@ return false;@b@ } else {@b@ return str.charAt(0) == prefix && str.charAt(str.length() - 1) == suffix;@b@ }@b@ }@b@@b@ public static String repeat(char c, int count) {@b@ if (count <= 0) {@b@ return "";@b@ } else {@b@ char[] result = new char[count];@b@@b@ for(int i = 0; i < count; ++i) {@b@ result[i] = c;@b@ }@b@@b@ return new String(result);@b@ }@b@ }@b@@b@ public static String repeat(CharSequence str, int count) {@b@ if (null == str) {@b@ return null;@b@ } else if (count <= 0) {@b@ return "";@b@ } else if (count != 1 && str.length() != 0) {@b@ int len = str.length();@b@ long longSize = (long)len * (long)count;@b@ int size = (int)longSize;@b@ if ((long)size != longSize) {@b@ throw new ArrayIndexOutOfBoundsException("Required String length is too large: " + longSize);@b@ } else {@b@ char[] array = new char[size];@b@ str.toString().getChars(0, len, array, 0);@b@@b@ int n;@b@ for(n = len; n < size - n; n <<= 1) {@b@ System.arraycopy(array, 0, array, n, n);@b@ }@b@@b@ System.arraycopy(array, 0, array, n, size - n);@b@ return new String(array);@b@ }@b@ } else {@b@ return str.toString();@b@ }@b@ }@b@@b@ public static String repeatByLength(CharSequence str, int padLen) {@b@ if (null == str) {@b@ return null;@b@ } else if (padLen <= 0) {@b@ return "";@b@ } else {@b@ int strLen = str.length();@b@ if (strLen == padLen) {@b@ return str.toString();@b@ } else if (strLen > padLen) {@b@ return subPre(str, padLen);@b@ } else {@b@ char[] padding = new char[padLen];@b@@b@ for(int i = 0; i < padLen; ++i) {@b@ padding[i] = str.charAt(i % padLen);@b@ }@b@@b@ return new String(padding);@b@ }@b@ }@b@ }@b@@b@ public static String repeatAndJoin(CharSequence str, int count, CharSequence conjunction) {@b@ if (count <= 0) {@b@ return "";@b@ } else {@b@ StrBuilder builder = StrBuilder.create();@b@@b@ for(boolean isFirst = true; count-- > 0; builder.append(str)) {@b@ if (isFirst) {@b@ isFirst = false;@b@ } else if (isNotEmpty(conjunction)) {@b@ builder.append(conjunction);@b@ }@b@ }@b@@b@ return builder.toString();@b@ }@b@ }@b@@b@ public static boolean equals(CharSequence str1, CharSequence str2) {@b@ return equals(str1, str2, false);@b@ }@b@@b@ public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {@b@ return equals(str1, str2, true);@b@ }@b@@b@ public static boolean equals(CharSequence str1, CharSequence str2, boolean ignoreCase) {@b@ if (null == str1) {@b@ return str2 == null;@b@ } else if (null == str2) {@b@ return false;@b@ } else {@b@ return ignoreCase ? str1.toString().equalsIgnoreCase(str2.toString()) : str1.equals(str2);@b@ }@b@ }@b@@b@ public static boolean equalsAnyIgnoreCase(CharSequence str1, CharSequence... strs) {@b@ return equalsAny(str1, true, strs);@b@ }@b@@b@ public static boolean equalsAny(CharSequence str1, CharSequence... strs) {@b@ return equalsAny(str1, false, strs);@b@ }@b@@b@ public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... strs) {@b@ if (ArrayUtil.isEmpty(strs)) {@b@ return false;@b@ } else {@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ if (equals(str1, str, ignoreCase)) {@b@ return true;@b@ }@b@ }@b@@b@ return false;@b@ }@b@ }@b@@b@ public static String format(CharSequence template, Object... params) {@b@ if (null == template) {@b@ return null;@b@ } else {@b@ return !ArrayUtil.isEmpty(params) && !isBlank(template) ? StrFormatter.format(template.toString(), params) : template.toString();@b@ }@b@ }@b@@b@ public static String indexedFormat(CharSequence pattern, Object... arguments) {@b@ return MessageFormat.format(pattern.toString(), arguments);@b@ }@b@@b@ public static String format(CharSequence template, Map<?, ?> map) {@b@ if (null == template) {@b@ return null;@b@ } else if (null != map && !map.isEmpty()) {@b@ String template2 = template.toString();@b@ Iterator i$ = map.entrySet().iterator();@b@@b@ while(i$.hasNext()) {@b@ Entry<?, ?> entry = (Entry)i$.next();@b@ String value = utf8Str(entry.getValue());@b@ if (null != value) {@b@ template2 = replace(template2, (CharSequence)("{" + entry.getKey() + "}"), (CharSequence)value);@b@ }@b@ }@b@@b@ return template2;@b@ } else {@b@ return template.toString();@b@ }@b@ }@b@@b@ public static byte[] utf8Bytes(CharSequence str) {@b@ return bytes(str, CharsetUtil.CHARSET_UTF_8);@b@ }@b@@b@ public static byte[] bytes(CharSequence str) {@b@ return bytes(str, Charset.defaultCharset());@b@ }@b@@b@ public static byte[] bytes(CharSequence str, String charset) {@b@ return bytes(str, isBlank(charset) ? Charset.defaultCharset() : Charset.forName(charset));@b@ }@b@@b@ public static byte[] bytes(CharSequence str, Charset charset) {@b@ if (str == null) {@b@ return null;@b@ } else {@b@ return null == charset ? str.toString().getBytes() : str.toString().getBytes(charset);@b@ }@b@ }@b@@b@ public static String utf8Str(Object obj) {@b@ return str(obj, CharsetUtil.CHARSET_UTF_8);@b@ }@b@@b@ public static String str(Object obj, String charsetName) {@b@ return str(obj, Charset.forName(charsetName));@b@ }@b@@b@ public static String str(Object obj, Charset charset) {@b@ if (null == obj) {@b@ return null;@b@ } else if (obj instanceof String) {@b@ return (String)obj;@b@ } else if (obj instanceof byte[]) {@b@ return str((byte[])((byte[])obj), charset);@b@ } else if (obj instanceof Byte[]) {@b@ return str((Byte[])((Byte[])obj), charset);@b@ } else if (obj instanceof ByteBuffer) {@b@ return str((ByteBuffer)obj, charset);@b@ } else {@b@ return ArrayUtil.isArray(obj) ? ArrayUtil.toString(obj) : obj.toString();@b@ }@b@ }@b@@b@ public static String str(byte[] bytes, String charset) {@b@ return str(bytes, isBlank(charset) ? Charset.defaultCharset() : Charset.forName(charset));@b@ }@b@@b@ public static String str(byte[] data, Charset charset) {@b@ if (data == null) {@b@ return null;@b@ } else {@b@ return null == charset ? new String(data) : new String(data, charset);@b@ }@b@ }@b@@b@ public static String str(Byte[] bytes, String charset) {@b@ return str(bytes, isBlank(charset) ? Charset.defaultCharset() : Charset.forName(charset));@b@ }@b@@b@ public static String str(Byte[] data, Charset charset) {@b@ if (data == null) {@b@ return null;@b@ } else {@b@ byte[] bytes = new byte[data.length];@b@@b@ for(int i = 0; i < data.length; ++i) {@b@ Byte dataByte = data[i];@b@ bytes[i] = null == dataByte ? -1 : dataByte;@b@ }@b@@b@ return str(bytes, charset);@b@ }@b@ }@b@@b@ public static String str(ByteBuffer data, String charset) {@b@ return data == null ? null : str(data, Charset.forName(charset));@b@ }@b@@b@ public static String str(ByteBuffer data, Charset charset) {@b@ if (null == charset) {@b@ charset = Charset.defaultCharset();@b@ }@b@@b@ return charset.decode(data).toString();@b@ }@b@@b@ public static String str(CharSequence cs) {@b@ return null == cs ? null : cs.toString();@b@ }@b@@b@ public static String toString(Object obj) {@b@ return null == obj ? "null" : obj.toString();@b@ }@b@@b@ public static ByteBuffer byteBuffer(CharSequence str, String charset) {@b@ return ByteBuffer.wrap(bytes(str, charset));@b@ }@b@@b@ public static String join(CharSequence conjunction, Object... objs) {@b@ return ArrayUtil.join(objs, conjunction);@b@ }@b@@b@ public static String toUnderlineCase(CharSequence str) {@b@ return toSymbolCase(str, '_');@b@ }@b@@b@ public static String toSymbolCase(CharSequence str, char symbol) {@b@ if (str == null) {@b@ return null;@b@ } else {@b@ int length = str.length();@b@ StringBuilder sb = new StringBuilder();@b@@b@ for(int i = 0; i < length; ++i) {@b@ char c = str.charAt(i);@b@ Character preChar = i > 0 ? str.charAt(i - 1) : null;@b@ if (Character.isUpperCase(c)) {@b@ Character nextChar = i < str.length() - 1 ? str.charAt(i + 1) : null;@b@ if (null != preChar && Character.isUpperCase(preChar)) {@b@ sb.append(c);@b@ } else if (null != nextChar && Character.isUpperCase(nextChar)) {@b@ if (null != preChar && symbol != preChar) {@b@ sb.append(symbol);@b@ }@b@@b@ sb.append(c);@b@ } else {@b@ if (null != preChar && symbol != preChar) {@b@ sb.append(symbol);@b@ }@b@@b@ sb.append(Character.toLowerCase(c));@b@ }@b@ } else {@b@ if (sb.length() > 0 && Character.isUpperCase(sb.charAt(sb.length() - 1)) && symbol != c) {@b@ sb.append(symbol);@b@ }@b@@b@ sb.append(c);@b@ }@b@ }@b@@b@ return sb.toString();@b@ }@b@ }@b@@b@ public static String toCamelCase(CharSequence name) {@b@ if (null == name) {@b@ return null;@b@ } else {@b@ String name2 = name.toString();@b@ if (name2.contains("_")) {@b@ StringBuilder sb = new StringBuilder(name2.length());@b@ boolean upperCase = false;@b@@b@ for(int i = 0; i < name2.length(); ++i) {@b@ char c = name2.charAt(i);@b@ if (c == '_') {@b@ upperCase = true;@b@ } else if (upperCase) {@b@ sb.append(Character.toUpperCase(c));@b@ upperCase = false;@b@ } else {@b@ sb.append(Character.toLowerCase(c));@b@ }@b@ }@b@@b@ return sb.toString();@b@ } else {@b@ return name2;@b@ }@b@ }@b@ }@b@@b@ public static String wrap(CharSequence str, CharSequence prefixAndSuffix) {@b@ return wrap(str, prefixAndSuffix, prefixAndSuffix);@b@ }@b@@b@ public static String wrap(CharSequence str, CharSequence prefix, CharSequence suffix) {@b@ return nullToEmpty(prefix).concat(nullToEmpty(str)).concat(nullToEmpty(suffix));@b@ }@b@@b@ public static String[] wrapAll(CharSequence prefixAndSuffix, CharSequence... strs) {@b@ return wrapAll(prefixAndSuffix, prefixAndSuffix, strs);@b@ }@b@@b@ public static String[] wrapAll(CharSequence prefix, CharSequence suffix, CharSequence... strs) {@b@ String[] results = new String[strs.length];@b@@b@ for(int i = 0; i < strs.length; ++i) {@b@ results[i] = wrap(strs[i], prefix, suffix);@b@ }@b@@b@ return results;@b@ }@b@@b@ public static String wrapIfMissing(CharSequence str, CharSequence prefix, CharSequence suffix) {@b@ int len = 0;@b@ if (isNotEmpty(str)) {@b@ len += str.length();@b@ }@b@@b@ if (isNotEmpty(prefix)) {@b@ len += str.length();@b@ }@b@@b@ if (isNotEmpty(suffix)) {@b@ len += str.length();@b@ }@b@@b@ StringBuilder sb = new StringBuilder(len);@b@ if (isNotEmpty(prefix) && !startWith(str, prefix)) {@b@ sb.append(prefix);@b@ }@b@@b@ if (isNotEmpty(str)) {@b@ sb.append(str);@b@ }@b@@b@ if (isNotEmpty(suffix) && !endWith(str, suffix)) {@b@ sb.append(suffix);@b@ }@b@@b@ return sb.toString();@b@ }@b@@b@ public static String[] wrapAllIfMissing(CharSequence prefixAndSuffix, CharSequence... strs) {@b@ return wrapAllIfMissing(prefixAndSuffix, prefixAndSuffix, strs);@b@ }@b@@b@ public static String[] wrapAllIfMissing(CharSequence prefix, CharSequence suffix, CharSequence... strs) {@b@ String[] results = new String[strs.length];@b@@b@ for(int i = 0; i < strs.length; ++i) {@b@ results[i] = wrapIfMissing(strs[i], prefix, suffix);@b@ }@b@@b@ return results;@b@ }@b@@b@ public static String unWrap(CharSequence str, String prefix, String suffix) {@b@ return isWrap(str, prefix, suffix) ? sub(str, prefix.length(), str.length() - suffix.length()) : str.toString();@b@ }@b@@b@ public static String unWrap(CharSequence str, char prefix, char suffix) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ return str.charAt(0) == prefix && str.charAt(str.length() - 1) == suffix ? sub(str, 1, str.length() - 1) : str.toString();@b@ }@b@ }@b@@b@ public static String unWrap(CharSequence str, char prefixAndSuffix) {@b@ return unWrap(str, prefixAndSuffix, prefixAndSuffix);@b@ }@b@@b@ public static boolean isWrap(CharSequence str, String prefix, String suffix) {@b@ if (ArrayUtil.hasNull(new CharSequence[]{str, prefix, suffix})) {@b@ return false;@b@ } else {@b@ String str2 = str.toString();@b@ return str2.startsWith(prefix) && str2.endsWith(suffix);@b@ }@b@ }@b@@b@ public static boolean isWrap(CharSequence str, String wrapper) {@b@ return isWrap(str, wrapper, wrapper);@b@ }@b@@b@ public static boolean isWrap(CharSequence str, char wrapper) {@b@ return isWrap(str, wrapper, wrapper);@b@ }@b@@b@ public static boolean isWrap(CharSequence str, char prefixChar, char suffixChar) {@b@ if (null == str) {@b@ return false;@b@ } else {@b@ return str.charAt(0) == prefixChar && str.charAt(str.length() - 1) == suffixChar;@b@ }@b@ }@b@@b@ public static String padPre(CharSequence str, int minLength, CharSequence padStr) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ int strLen = str.length();@b@ if (strLen == minLength) {@b@ return str.toString();@b@ } else {@b@ return strLen > minLength ? subPre(str, minLength) : repeat(padStr, minLength - strLen).concat(str.toString());@b@ }@b@ }@b@ }@b@@b@ public static String padPre(CharSequence str, int minLength, char padChar) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ int strLen = str.length();@b@ if (strLen == minLength) {@b@ return str.toString();@b@ } else {@b@ return strLen > minLength ? subPre(str, minLength) : repeat(padChar, minLength - strLen).concat(str.toString());@b@ }@b@ }@b@ }@b@@b@ public static String padAfter(CharSequence str, int minLength, char padChar) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ int strLen = str.length();@b@ if (strLen == minLength) {@b@ return str.toString();@b@ } else {@b@ return strLen > minLength ? sub(str, strLen - minLength, strLen) : str.toString().concat(repeat(padChar, minLength - strLen));@b@ }@b@ }@b@ }@b@@b@ public static String padAfter(CharSequence str, int minLength, CharSequence padStr) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ int strLen = str.length();@b@ if (strLen == minLength) {@b@ return str.toString();@b@ } else {@b@ return strLen > minLength ? subSuf(str, minLength) : str.toString().concat(repeat(padStr, minLength - strLen));@b@ }@b@ }@b@ }@b@@b@ public static String center(CharSequence str, int size) {@b@ return center(str, size, ' ');@b@ }@b@@b@ public static String center(CharSequence str, int size, char padChar) {@b@ if (str != null && size > 0) {@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0) {@b@ return str.toString();@b@ } else {@b@ CharSequence str = padPre(str, strLen + pads / 2, padChar);@b@ str = padAfter(str, size, padChar);@b@ return str.toString();@b@ }@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String center(CharSequence str, int size, CharSequence padStr) {@b@ if (str != null && size > 0) {@b@ if (isEmpty((CharSequence)padStr)) {@b@ padStr = " ";@b@ }@b@@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0) {@b@ return str.toString();@b@ } else {@b@ CharSequence str = padPre(str, strLen + pads / 2, (CharSequence)padStr);@b@ str = padAfter(str, size, (CharSequence)padStr);@b@ return str.toString();@b@ }@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static StringBuilder builder() {@b@ return new StringBuilder();@b@ }@b@@b@ public static StrBuilder strBuilder() {@b@ return StrBuilder.create();@b@ }@b@@b@ public static StringBuilder builder(int capacity) {@b@ return new StringBuilder(capacity);@b@ }@b@@b@ public static StrBuilder strBuilder(int capacity) {@b@ return StrBuilder.create(capacity);@b@ }@b@@b@ public static StringBuilder builder(CharSequence... strs) {@b@ StringBuilder sb = new StringBuilder();@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ sb.append(str);@b@ }@b@@b@ return sb;@b@ }@b@@b@ public static StrBuilder strBuilder(CharSequence... strs) {@b@ return StrBuilder.create(strs);@b@ }@b@@b@ public static StringReader getReader(CharSequence str) {@b@ return null == str ? null : new StringReader(str.toString());@b@ }@b@@b@ public static StringWriter getWriter() {@b@ return new StringWriter();@b@ }@b@@b@ public static int count(CharSequence content, CharSequence strForSearch) {@b@ if (!hasEmpty(content, strForSearch) && strForSearch.length() <= content.length()) {@b@ int count = 0;@b@ int idx = 0;@b@ String content2 = content.toString();@b@@b@ for(String strForSearch2 = strForSearch.toString(); (idx = content2.indexOf(strForSearch2, idx)) > -1; idx += strForSearch.length()) {@b@ ++count;@b@ }@b@@b@ return count;@b@ } else {@b@ return 0;@b@ }@b@ }@b@@b@ public static int count(CharSequence content, char charForSearch) {@b@ int count = 0;@b@ if (isEmpty(content)) {@b@ return 0;@b@ } else {@b@ int contentLength = content.length();@b@@b@ for(int i = 0; i < contentLength; ++i) {@b@ if (charForSearch == content.charAt(i)) {@b@ ++count;@b@ }@b@ }@b@@b@ return count;@b@ }@b@ }@b@@b@ public static String[] cut(CharSequence str, int partLength) {@b@ if (null == str) {@b@ return null;@b@ } else {@b@ int len = str.length();@b@ if (len < partLength) {@b@ return new String[]{str.toString()};@b@ } else {@b@ int part = NumberUtil.count(len, partLength);@b@ String[] array = new String[part];@b@ String str2 = str.toString();@b@@b@ for(int i = 0; i < part; ++i) {@b@ array[i] = str2.substring(i * partLength, i == part - 1 ? len : partLength + i * partLength);@b@ }@b@@b@ return array;@b@ }@b@ }@b@ }@b@@b@ public static String brief(CharSequence str, int maxLength) {@b@ if (null == str) {@b@ return null;@b@ } else if (str.length() + 3 <= maxLength) {@b@ return str.toString();@b@ } else {@b@ int w = maxLength / 2;@b@ int l = str.length();@b@ String str2 = str.toString();@b@ return format("{}...{}", (Object[])(str2.substring(0, maxLength - w), str2.substring(l - w)));@b@ }@b@ }@b@@b@ public static int compare(CharSequence str1, CharSequence str2, boolean nullIsLess) {@b@ if (str1 == str2) {@b@ return 0;@b@ } else if (str1 == null) {@b@ return nullIsLess ? -1 : 1;@b@ } else if (str2 == null) {@b@ return nullIsLess ? 1 : -1;@b@ } else {@b@ return str1.toString().compareTo(str2.toString());@b@ }@b@ }@b@@b@ public static int compareIgnoreCase(CharSequence str1, CharSequence str2, boolean nullIsLess) {@b@ if (str1 == str2) {@b@ return 0;@b@ } else if (str1 == null) {@b@ return nullIsLess ? -1 : 1;@b@ } else if (str2 == null) {@b@ return nullIsLess ? 1 : -1;@b@ } else {@b@ return str1.toString().compareToIgnoreCase(str2.toString());@b@ }@b@ }@b@@b@ public static int compareVersion(CharSequence version1, CharSequence version2) {@b@ return VersionComparator.INSTANCE.compare(str(version1), str(version2));@b@ }@b@@b@ public static int indexOf(CharSequence str, char searchChar) {@b@ return indexOf(str, searchChar, 0);@b@ }@b@@b@ public static int indexOf(CharSequence str, char searchChar, int start) {@b@ return str instanceof String ? ((String)str).indexOf(searchChar, start) : indexOf(str, searchChar, start, -1);@b@ }@b@@b@ public static int indexOf(CharSequence str, char searchChar, int start, int end) {@b@ int len = str.length();@b@ if (start < 0 || start > len) {@b@ start = 0;@b@ }@b@@b@ if (end > len || end < 0) {@b@ end = len;@b@ }@b@@b@ for(int i = start; i < end; ++i) {@b@ if (str.charAt(i) == searchChar) {@b@ return i;@b@ }@b@ }@b@@b@ return -1;@b@ }@b@@b@ public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr) {@b@ return indexOfIgnoreCase(str, searchStr, 0);@b@ }@b@@b@ public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int fromIndex) {@b@ return indexOf(str, searchStr, fromIndex, true);@b@ }@b@@b@ public static int indexOf(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) {@b@ if (str != null && searchStr != null) {@b@ if (fromIndex < 0) {@b@ fromIndex = 0;@b@ }@b@@b@ int endLimit = str.length() - searchStr.length() + 1;@b@ if (fromIndex > endLimit) {@b@ return -1;@b@ } else if (searchStr.length() == 0) {@b@ return fromIndex;@b@ } else if (!ignoreCase) {@b@ return str.toString().indexOf(searchStr.toString(), fromIndex);@b@ } else {@b@ for(int i = fromIndex; i < endLimit; ++i) {@b@ if (isSubEquals(str, i, searchStr, 0, searchStr.length(), true)) {@b@ return i;@b@ }@b@ }@b@@b@ return -1;@b@ }@b@ } else {@b@ return -1;@b@ }@b@ }@b@@b@ public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr) {@b@ return lastIndexOfIgnoreCase(str, searchStr, str.length());@b@ }@b@@b@ public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr, int fromIndex) {@b@ return lastIndexOf(str, searchStr, fromIndex, true);@b@ }@b@@b@ public static int lastIndexOf(CharSequence str, CharSequence searchStr, int fromIndex, boolean ignoreCase) {@b@ if (str != null && searchStr != null) {@b@ if (fromIndex < 0) {@b@ fromIndex = 0;@b@ }@b@@b@ fromIndex = Math.min(fromIndex, str.length());@b@ if (searchStr.length() == 0) {@b@ return fromIndex;@b@ } else if (!ignoreCase) {@b@ return str.toString().lastIndexOf(searchStr.toString(), fromIndex);@b@ } else {@b@ for(int i = fromIndex; i > 0; --i) {@b@ if (isSubEquals(str, i, searchStr, 0, searchStr.length(), true)) {@b@ return i;@b@ }@b@ }@b@@b@ return -1;@b@ }@b@ } else {@b@ return -1;@b@ }@b@ }@b@@b@ public static int ordinalIndexOf(String str, String searchStr, int ordinal) {@b@ if (str != null && searchStr != null && ordinal > 0) {@b@ if (searchStr.length() == 0) {@b@ return 0;@b@ } else {@b@ int found = 0;@b@ int index = -1;@b@@b@ do {@b@ index = str.indexOf(searchStr, index + 1);@b@ if (index < 0) {@b@ return index;@b@ }@b@@b@ ++found;@b@ } while(found < ordinal);@b@@b@ return index;@b@ }@b@ } else {@b@ return -1;@b@ }@b@ }@b@@b@ public static String appendIfMissing(CharSequence str, CharSequence suffix, CharSequence... suffixes) {@b@ return appendIfMissing(str, suffix, false, suffixes);@b@ }@b@@b@ public static String appendIfMissingIgnoreCase(CharSequence str, CharSequence suffix, CharSequence... suffixes) {@b@ return appendIfMissing(str, suffix, true, suffixes);@b@ }@b@@b@ public static String appendIfMissing(CharSequence str, CharSequence suffix, boolean ignoreCase, CharSequence... suffixes) {@b@ if (str != null && !isEmpty(suffix) && !endWith(str, suffix, ignoreCase)) {@b@ if (suffixes != null && suffixes.length > 0) {@b@ CharSequence[] arr$ = suffixes;@b@ int len$ = suffixes.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence s = arr$[i$];@b@ if (endWith(str, s, ignoreCase)) {@b@ return str.toString();@b@ }@b@ }@b@ }@b@@b@ return str.toString().concat(suffix.toString());@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String prependIfMissing(CharSequence str, CharSequence prefix, CharSequence... prefixes) {@b@ return prependIfMissing(str, prefix, false, prefixes);@b@ }@b@@b@ public static String prependIfMissingIgnoreCase(CharSequence str, CharSequence prefix, CharSequence... prefixes) {@b@ return prependIfMissing(str, prefix, true, prefixes);@b@ }@b@@b@ public static String prependIfMissing(CharSequence str, CharSequence prefix, boolean ignoreCase, CharSequence... prefixes) {@b@ if (str != null && !isEmpty(prefix) && !startWith(str, prefix, ignoreCase)) {@b@ if (prefixes != null && prefixes.length > 0) {@b@ CharSequence[] arr$ = prefixes;@b@ int len$ = prefixes.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence s = arr$[i$];@b@ if (startWith(str, s, ignoreCase)) {@b@ return str.toString();@b@ }@b@ }@b@ }@b@@b@ return prefix.toString().concat(str.toString());@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String reverse(String str) {@b@ return new String(ArrayUtil.reverse(str.toCharArray()));@b@ }@b@@b@ public static String fillBefore(String str, char filledChar, int len) {@b@ return fill(str, filledChar, len, true);@b@ }@b@@b@ public static String fillAfter(String str, char filledChar, int len) {@b@ return fill(str, filledChar, len, false);@b@ }@b@@b@ public static String fill(String str, char filledChar, int len, boolean isPre) {@b@ int strLen = str.length();@b@ if (strLen > len) {@b@ return str;@b@ } else {@b@ String filledStr = repeat(filledChar, len - strLen);@b@ return isPre ? filledStr.concat(str) : str.concat(filledStr);@b@ }@b@ }@b@@b@ public static boolean isSubEquals(CharSequence str1, int start1, CharSequence str2, int start2, int length, boolean ignoreCase) {@b@ return null != str1 && null != str2 ? str1.toString().regionMatches(ignoreCase, start1, str2.toString(), start2, length) : false;@b@ }@b@@b@ public static boolean isAllCharMatch(CharSequence value, Matcher<Character> matcher) {@b@ if (isBlank(value)) {@b@ return false;@b@ } else {@b@ int len = value.length();@b@ boolean isAllMatch = true;@b@@b@ for(int i = 0; i < len; ++i) {@b@ isAllMatch &= matcher.match(value.charAt(i));@b@ }@b@@b@ return isAllMatch;@b@ }@b@ }@b@@b@ public static String replaceIgnoreCase(CharSequence str, CharSequence searchStr, CharSequence replacement) {@b@ return replace(str, 0, searchStr, replacement, true);@b@ }@b@@b@ public static String replace(CharSequence str, CharSequence searchStr, CharSequence replacement) {@b@ return replace(str, 0, searchStr, replacement, false);@b@ }@b@@b@ public static String replace(CharSequence str, CharSequence searchStr, CharSequence replacement, boolean ignoreCase) {@b@ return replace(str, 0, searchStr, replacement, ignoreCase);@b@ }@b@@b@ public static String replace(CharSequence str, int fromIndex, CharSequence searchStr, CharSequence replacement, boolean ignoreCase) {@b@ if (!isEmpty(str) && !isEmpty(searchStr)) {@b@ if (null == replacement) {@b@ replacement = "";@b@ }@b@@b@ int strLength = str.length();@b@ int searchStrLength = searchStr.length();@b@ if (fromIndex > strLength) {@b@ return str(str);@b@ } else {@b@ if (fromIndex < 0) {@b@ fromIndex = 0;@b@ }@b@@b@ StrBuilder result = StrBuilder.create(strLength + 16);@b@ if (0 != fromIndex) {@b@ result.append(str.subSequence(0, fromIndex));@b@ }@b@@b@ int preIndex;@b@ int index;@b@ for(preIndex = fromIndex; (index = indexOf(str, searchStr, preIndex, ignoreCase)) > -1; preIndex = index + searchStrLength) {@b@ result.append(str.subSequence(preIndex, index));@b@ result.append((CharSequence)replacement);@b@ }@b@@b@ if (preIndex < strLength) {@b@ result.append(str.subSequence(preIndex, strLength));@b@ }@b@@b@ return result.toString();@b@ }@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static String replace(CharSequence str, int startInclude, int endExclude, char replacedChar) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int strLength = str.length();@b@ if (startInclude > strLength) {@b@ return str(str);@b@ } else {@b@ if (endExclude > strLength) {@b@ endExclude = strLength;@b@ }@b@@b@ if (startInclude > endExclude) {@b@ return str(str);@b@ } else {@b@ char[] chars = new char[strLength];@b@@b@ for(int i = 0; i < strLength; ++i) {@b@ if (i >= startInclude && i < endExclude) {@b@ chars[i] = replacedChar;@b@ } else {@b@ chars[i] = str.charAt(i);@b@ }@b@ }@b@@b@ return new String(chars);@b@ }@b@ }@b@ }@b@ }@b@@b@ public static String replace(CharSequence str, Pattern pattern, Func1<java.util.regex.Matcher, String> replaceFun) {@b@ return ReUtil.replaceAll(str, pattern, replaceFun);@b@ }@b@@b@ public static String replace(CharSequence str, String regex, Func1<java.util.regex.Matcher, String> replaceFun) {@b@ return ReUtil.replaceAll(str, regex, replaceFun);@b@ }@b@@b@ public static String hide(CharSequence str, int startInclude, int endExclude) {@b@ return replace(str, startInclude, endExclude, '*');@b@ }@b@@b@ public static String replaceChars(CharSequence str, String chars, CharSequence replacedStr) {@b@ return !isEmpty(str) && !isEmpty(chars) ? replaceChars(str, chars.toCharArray(), replacedStr) : str(str);@b@ }@b@@b@ public static String replaceChars(CharSequence str, char[] chars, CharSequence replacedStr) {@b@ if (!isEmpty(str) && !ArrayUtil.isEmpty(chars)) {@b@ Set<Character> set = new HashSet(chars.length);@b@ char[] arr$ = chars;@b@ int len$ = chars.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ char c = arr$[i$];@b@ set.add(c);@b@ }@b@@b@ int strLen = str.length();@b@ StringBuilder builder = builder();@b@@b@ for(int i = 0; i < strLen; ++i) {@b@ char c = str.charAt(i);@b@ builder.append(set.contains(c) ? replacedStr : c);@b@ }@b@@b@ return builder.toString();@b@ } else {@b@ return str(str);@b@ }@b@ }@b@@b@ public static double similar(String str1, String str2) {@b@ return TextSimilarity.similar(str1, str2);@b@ }@b@@b@ public static String similar(String str1, String str2, int scale) {@b@ return TextSimilarity.similar(str1, str2, scale);@b@ }@b@@b@ public static boolean equalsCharAt(CharSequence str, int position, char c) {@b@ if (null != str && position >= 0) {@b@ return str.length() > position && c == str.charAt(position);@b@ } else {@b@ return false;@b@ }@b@ }@b@@b@ public static int totalLength(CharSequence... strs) {@b@ int totalLength = 0;@b@@b@ for(int i = 0; i < strs.length; ++i) {@b@ totalLength += null == strs[i] ? 0 : strs[i].length();@b@ }@b@@b@ return totalLength;@b@ }@b@@b@ public static String move(CharSequence str, int startInclude, int endExclude, int moveLength) {@b@ if (isEmpty(str)) {@b@ return str(str);@b@ } else {@b@ int len = str.length();@b@ if (Math.abs(moveLength) > len) {@b@ moveLength %= len;@b@ }@b@@b@ StrBuilder strBuilder = StrBuilder.create(len);@b@ int startAfterMove;@b@ if (moveLength > 0) {@b@ startAfterMove = Math.min(endExclude + moveLength, str.length());@b@ strBuilder.append(str.subSequence(0, startInclude)).append(str.subSequence(endExclude, startAfterMove)).append(str.subSequence(startInclude, endExclude)).append(str.subSequence(startAfterMove, str.length()));@b@ } else {@b@ if (moveLength >= 0) {@b@ return str(str);@b@ }@b@@b@ startAfterMove = Math.max(startInclude + moveLength, 0);@b@ strBuilder.append(str.subSequence(0, startAfterMove)).append(str.subSequence(startInclude, endExclude)).append(str.subSequence(startAfterMove, startInclude)).append(str.subSequence(endExclude, str.length()));@b@ }@b@@b@ return strBuilder.toString();@b@ }@b@ }@b@@b@ public static String uuid() {@b@ return IdUtil.randomUUID();@b@ }@b@@b@ public static String concat(boolean isNullToEmpty, CharSequence... strs) {@b@ StrBuilder sb = new StrBuilder();@b@ CharSequence[] arr$ = strs;@b@ int len$ = strs.length;@b@@b@ for(int i$ = 0; i$ < len$; ++i$) {@b@ CharSequence str = arr$[i$];@b@ sb.append((CharSequence)(isNullToEmpty ? nullToEmpty(str) : str));@b@ }@b@@b@ return sb.toString();@b@ }@b@@b@ public static boolean isUpperCase(CharSequence str) {@b@ if (null == str) {@b@ return false;@b@ } else {@b@ int len = str.length();@b@@b@ for(int i = 0; i < len; ++i) {@b@ if (Character.isLowerCase(str.charAt(i))) {@b@ return false;@b@ }@b@ }@b@@b@ return true;@b@ }@b@ }@b@@b@ public static boolean isLowerCase(CharSequence str) {@b@ if (null == str) {@b@ return false;@b@ } else {@b@ int len = str.length();@b@@b@ for(int i = 0; i < len; ++i) {@b@ if (Character.isUpperCase(str.charAt(i))) {@b@ return false;@b@ }@b@ }@b@@b@ return true;@b@ }@b@ }@b@@b@ public static int length(CharSequence cs) {@b@ return cs == null ? 0 : cs.length();@b@ }@b@@b@ public static String swapCase(String str) {@b@ if (isEmpty(str)) {@b@ return str;@b@ } else {@b@ char[] buffer = str.toCharArray();@b@@b@ for(int i = 0; i < buffer.length; ++i) {@b@ char ch = buffer[i];@b@ if (Character.isUpperCase(ch)) {@b@ buffer[i] = Character.toLowerCase(ch);@b@ } else if (Character.isTitleCase(ch)) {@b@ buffer[i] = Character.toLowerCase(ch);@b@ } else if (Character.isLowerCase(ch)) {@b@ buffer[i] = Character.toUpperCase(ch);@b@ }@b@ }@b@@b@ return new String(buffer);@b@ }@b@ }@b@}