package tools.string;

public class StringTool {
	/**
	 * delete space at end of script
	 * 
	 * @param s
	 * @return
	 */
	public static String deleteEndSpace(String s) {
		while (s != null && !s.isEmpty() && isSpace(s.charAt(s.length() - 1))) {
			s = s.substring(0, s.length() - 1);
		}
		return s;
	}

	/**
	 * delete space at begin of script
	 * 
	 * @param s
	 * @return
	 */
	public static String deleteBeginSpace(String s) {
		while (s != null & !s.isEmpty() && isSpace(s.charAt(0))) {
			s = s.substring(1);
		}
		return s;
	}

	/**
	 * returns true if given character is a space or cr or lf
	 * 
	 * @param c
	 * @return
	 */
	public static boolean isSpace(char c) {
		return c == ' ' || c == '\n' || c == '\t' || c == '\r';
	}
}
