
com.github.siwenyan.common.StringUtils Maven / Gradle / Ivy
package com.github.siwenyan.common;
public class StringUtils {
public static boolean isEmpty(String s) {
return null == s || s.trim().isEmpty() || s.trim().matches("-*");
}
public static String peel(String raw) {
if (null == raw) {
return null;
}
raw = raw.trim();
while (raw.length() > 1 && isWrapped(raw)) {
raw = raw.substring(1, raw.length() - 1);
}
return raw;
}
private static boolean isWrapped(String raw) {
for (String[] pair : PEEL_PAIRS) {
if (raw.startsWith(pair[0]) && raw.endsWith(pair[1])
&& (raw.indexOf(pair[0], 1) < 0 || raw.length() - 1 == raw.indexOf(pair[0], 1))
&& (raw.indexOf(pair[1], 1) < 0 || raw.length() - 1 == raw.indexOf(pair[1], 1))
) {
return true;
}
}
return false;
}
private static final String[][] PEEL_PAIRS = {{"{", "}"}, {"[", "]"}, {"(", ")"}, {"\"", "\""},
{"'", "'"}};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy