List of utility methods to do String Chomp
String | chomp(String str) chomp if (isEmpty(str)) { return str; if (str.length() == 1) { char ch = str.charAt(0); if ((ch == '\r') || (ch == '\n')) { return ""; return str; int lastIdx = str.length() - 1; char last = str.charAt(lastIdx); if (last == '\n') { if (str.charAt(lastIdx - 1) == '\r') { lastIdx--; } else if (last != '\r') { lastIdx++; return str.substring(0, lastIdx); |
String | chomp(String str) Remove all whitespace from the start and end of a string. if (str == null || str.length() == 0) { return str; int firstIdx = 0; int lastIdx = str.length() - 1; char c = str.charAt(lastIdx); while (c == '\n' || c == '\r' || c == '\t' || c == ' ') { if (lastIdx == 0) { ... |
String | chomp(String str) chomp return chomp(str, "\n"); |
String | chomp(String str) Removes last character if it is a newline. if (str.endsWith("\n")) { return str.substring(0, str.length() - 1); } else { return str; |
String | chomp(String str, String sep) Remove the last value of a supplied String, and everything after it from a String. int idx = str.lastIndexOf(sep); if (idx != -1) { return str.substring(0, idx); } else { return str; |
String | chomp(String str, String separator) Removes NOTE: This method changed in version 2.0. if (isEmpty(str) || separator == null) { return str; if (str.endsWith(separator)) { return str.substring(0, str.length() - separator.length()); return str; |
String | chomp(String value) chomp if (value.length() > 0) { return value.substring(0, value.length() - 1); return value; |
void | chomp(StringBuilder sb) chomp chopIfMatch(sb, '\n'); chopIfMatch(sb, '\r'); |
String | chompAllAndTrim(String str) Remove the end of line and tab characters from a String. StringBuffer buffer = new StringBuffer(); for (int i = 0; i < str.length(); i++) { if (str.charAt(i) != '\n' && str.charAt(i) != '\r' && str.charAt(i) != '\t') buffer.append(str.charAt(i)); str = buffer.toString(); buffer = null; return str; ... |
String | chompClosureOpen(String expr) chomp Closure Open if (!expr.endsWith("{")) { return expr; int closurePos = expr.lastIndexOf("->"); if (closurePos < 0) { return expr; return expr.substring(0, closurePos).trim(); ... |