com.xqbase.util.Strings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xqbase-util-jdk17 Show documentation
Show all versions of xqbase-util-jdk17 Show documentation
Reusable Java components for www.xqbase.com
package com.xqbase.util;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class Strings {
public static boolean isEmpty(String s) {
return s == null || s.isEmpty();
}
public static boolean isBlank(String s) {
return s == null || s.trim().isEmpty();
}
public static String truncate(String s, int len) {
return s == null ? "" : s.length() > len ? s.substring(0, len) : s;
}
public static String encodeUrl(String s) {
try {
return s == null ? "" : URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
public static String decodeUrl(String s) {
try {
return s == null ? "" : URLDecoder.decode(s, "UTF-8");
} catch (IllegalArgumentException e) {
return "";
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}