X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FStringUtils.java;h=89bc36d65d72904132bc833a3b62c83130a5e5a9;hb=ae3fad8019274ca3ab1258a480ba15dd9adac1e9;hp=7e1b8ad2c86bcf0c82a585fb33defe63b9c94676;hpb=d2259df2688d404ac89f6dfed3921280a5038c7b;p=jalview.git diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java index 7e1b8ad..89bc36d 100644 --- a/src/jalview/util/StringUtils.java +++ b/src/jalview/util/StringUtils.java @@ -202,18 +202,18 @@ public class StringUtils jv.clear(); if (DEBUG) { - System.err.println("Array from '" + delimiter + jalview.bin.Console.errPrintln("Array from '" + delimiter + "' separated List:\n" + v.length); for (int i = 0; i < v.length; i++) { - System.err.println("item " + i + " '" + v[i] + "'"); + jalview.bin.Console.errPrintln("item " + i + " '" + v[i] + "'"); } } return v; } if (DEBUG) { - System.err.println( + jalview.bin.Console.errPrintln( "Empty Array from '" + delimiter + "' separated List"); } return null; @@ -249,13 +249,13 @@ public class StringUtils { System.err .println("Returning '" + separator + "' separated List:\n"); - System.err.println(v); + jalview.bin.Console.errPrintln(v); } return v.toString(); } if (DEBUG) { - System.err.println( + jalview.bin.Console.errPrintln( "Returning empty '" + separator + "' separated List\n"); } return "" + separator; @@ -586,6 +586,15 @@ public class StringUtils return min < text.length() + 1 ? min : -1; } + public static boolean equalsIgnoreCase(String s1, String s2) + { + if (s1 == null || s2 == null) + { + return s1 == s2; + } + return s1.toLowerCase(Locale.ROOT).equals(s2.toLowerCase(Locale.ROOT)); + } + public static int indexOfFirstWhitespace(String text) { int index = -1; @@ -600,6 +609,7 @@ public class StringUtils /* * implementation of String.replaceLast. + * Replaces only the last occurrence of toReplace in string with replacement. */ public static String replaceLast(String string, String toReplace, String replacement) @@ -607,13 +617,31 @@ public class StringUtils int pos = string.lastIndexOf(toReplace); if (pos > -1) { - return string.substring(0, pos) + replacement - + string.substring(pos + toReplace.length()); + return new StringBuilder().append(string.substring(0, pos)) + .append(replacement) + .append(string.substring(pos + toReplace.length())) + .toString(); } else { return string; } + } + /* + * return the maximum length of a List of Strings + */ + public static int maxLength(List l) + { + int max = 0; + for (String s : l) + { + if (s == null) + continue; + if (s.length() > max) + max = s.length(); + } + return max; + } }