code: public static String chomp(String str) {
        if (isEmpty(str)) {
            return str;
        }
  
        if (str.length() == 1) {
            char ch = str.charAt(0);
            if (ch == '\r' || ch == '\n') {
                return EMPTY;
            }
            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);
    }
docs: <p>Removes one newline from end of a String if it's there,
  otherwise leave it alone.  A newline is &quot;<code>\n</code>&quot;,
  &quot;<code>\r</code>&quot;, or &quot;<code>\r\n</code>&quot;.</p>
  
  <p>NOTE: This method changed in 2.0.
  It now more closely matches Perl chomp.</p>
  
  <pre>
  GosuStringUtil.chomp(null)          = null
  GosuStringUtil.chomp("")            = ""
  GosuStringUtil.chomp("abc \r")      = "abc "
  GosuStringUtil.chomp("abc\n")       = "abc"
  GosuStringUtil.chomp("abc\r\n")     = "abc"
  GosuStringUtil.chomp("abc\r\n\r\n") = "abc\r\n"
  GosuStringUtil.chomp("abc\n\r")     = "abc\n"
  GosuStringUtil.chomp("abc\n\rabc")  = "abc\n\rabc"
  GosuStringUtil.chomp("\r")          = ""
  GosuStringUtil.chomp("\n")          = ""
  GosuStringUtil.chomp("\r\n")        = ""
  </pre>
  
  @param str  the String to chomp a newline from, may be null
  @return String without newline, <code>null</code> if null String input