|
@@ -706,33 +706,31 @@ public final class StringUtils {
|
|
|
public static <T, U, R> R decompose(String text, @NonNull BiFunction<T, U, R> builder,
|
|
|
@NonNull Function<String, T> parser1,
|
|
|
@NonNull BiFunction<String, T, U> parser2) {
|
|
|
- if (isEmpty(text) || (text = text.trim()).isEmpty()) {
|
|
|
+ if (isEmpty(text) || (text = text.trim()).isEmpty()
|
|
|
+ || (text.charAt(0) == '(' && text.charAt(text.length() - 1) == ')'
|
|
|
+ && (text = text.substring(1, text.length() - 1).trim()).isEmpty())) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- T first = null;
|
|
|
- U second = null;
|
|
|
- if (text.charAt(0) == '(' && text.charAt(text.length() - 1) == ')') {
|
|
|
- text = text.substring(1, text.length() - 1);
|
|
|
- }
|
|
|
- if ((text = text.trim()).isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String item;
|
|
|
+ // 获取分隔符下标位置
|
|
|
int delimiter = -1;
|
|
|
for (int i = 0, max = text.length(); i < max; i++) {
|
|
|
char c = text.charAt(i);
|
|
|
- if (c == '\t' || c == ';' || c == ',') {
|
|
|
+ if (c == '_' || c == ',') {
|
|
|
delimiter = i;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 字符串解析
|
|
|
+ String item;
|
|
|
+ T first = null;
|
|
|
+ U second = null;
|
|
|
if (delimiter < 0) {
|
|
|
first = parser1.apply(text);
|
|
|
} else if (delimiter == 0 && !(item = text.substring(1).trim()).isEmpty()) {
|
|
|
second = parser2.apply(item, null);
|
|
|
- } else if (delimiter == text.length() - 1
|
|
|
- && !(item = text.substring(0, text.length() - 1).trim()).isEmpty()) {
|
|
|
+ } else if (delimiter == text.length() - 1 && !(item = text.substring(0, text.length() - 1).trim()).isEmpty()) {
|
|
|
first = parser1.apply(item);
|
|
|
} else if (delimiter > 0 && delimiter < text.length() - 1) {
|
|
|
if (!(item = text.substring(0, delimiter).trim()).isEmpty()) {
|