
com.duoec.doc.utils.StringUtils Maven / Gradle / Ivy
package com.duoec.doc.utils;
import com.duoec.doc.constants.DuoDocletConstants;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author xuwenzhen
*/
public class StringUtils {
private static final Pattern VALUE_PATTERN = Pattern.compile("^\"(.*)\"$");
private StringUtils() {
}
public static boolean isEmpty(String str) {
if (str == null) {
return true;
}
return str.length() == 0;
}
public static boolean isNotEmpty(String str) {
return !isEmpty(str);
}
public static String firstLine(String str) {
if (isEmpty(str)) {
return null;
}
return str.split(DuoDocletConstants.TURN_LINE_STRING)[0];
}
public static String afterFirstLine(String str) {
if (isEmpty(str)) {
return null;
}
int index = str.indexOf(DuoDocletConstants.TURN_LINE_STRING);
if (index == -1) {
return null;
}
return str.substring(index + 1);
}
public static Integer tryParseInt(String str) {
if (isEmpty(str)) {
return null;
}
final int sz = str.length();
for (int i = 0; i < sz; i++) {
if (!Character.isDigit(str.charAt(i))) {
return null;
}
}
return Integer.parseInt(str);
}
/**
* 删除双引号
*
* @param str 字符串
* @return 删除双引号后的字符串
*/
public static String cleanQuotation(String str) {
if (isEmpty(str)) {
return str;
}
Matcher matcher = VALUE_PATTERN.matcher(str);
if (matcher.find()) {
return matcher.group(1);
}
return str;
}
public static String join(List list, String joiner) {
if (CollectionUtils.isEmpty(list)) {
return null;
}
StringBuilder sb = new StringBuilder();
for (String s : list) {
sb.append(s).append(joiner);
}
return sb.substring(0, sb.length() - joiner.length());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy