import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils
cp = pos + seplen;
wasescaped = escape == -1;
// last separator may be in an unmatched quote
+ // private static final Pattern DELIMITERS_PATTERN =
+ // Pattern.compile(".*='[^']*(?!')");
wasquoted = DELIMITERS_PATTERN.matcher(lstitem).matches();
}
if (cp < input.length())
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;
{
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;
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;
- Pattern pat = Pattern.compile("\\s");
- Matcher m = pat.matcher(text);
- if (m.find())
+ // Rewritten to not use regex for Jalviewjs. Probably more efficient this
+ // way anyway.
+ if (text == null)
{
- index = m.start();
+ return -1;
}
- return index;
+ for (int i = 0; i < text.length(); i++)
+ {
+ if (Character.isWhitespace(text.charAt(i)))
+ {
+ return i;
+ }
+ }
+ return -1;
}
/*
* 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)
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<String> l)
+ {
+ int max = 0;
+ for (String s : l)
+ {
+ if (s == null)
+ continue;
+ if (s.length() > max)
+ max = s.length();
+ }
+ return max;
+ }
}