All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xqbase.util.Strings Maven / Gradle / Ivy

There is a newer version: 0.2.18
Show newest version
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy