static S fixNewLines(S s) { int i = indexOf(s, '\r'); if (i < 0) ret s; int l = s.length(); StringBuilder out = new(l); out.append(s, 0, i); for (; i < l; i++) { char c = s.charAt(i); if (c != '\r') out.append(c); else { out.append('\n'); if (i+1 < l && s.charAt(i+1) == '\n') ++i; } } ret out.toString(); }