X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FStringUtils.java;fp=src%2Fjalview%2Futil%2FStringUtils.java;h=c7a8f33d4fc3be51587e174ac18b0a002859db0c;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=3025e8a328f4e156d7fa685aa53714268cc38eb4;hpb=49db0dff1da16c3355b43a41498c1fc93ef47e91;p=jalview.git diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java index 3025e8a..c7a8f33 100644 --- a/src/jalview/util/StringUtils.java +++ b/src/jalview/util/StringUtils.java @@ -119,6 +119,29 @@ public class StringUtils } /** + * Returns the last part of 'input' after the last occurrence of 'token'. For + * example to extract only the filename from a full path or URL. + * + * @param input + * @param token + * a delimiter which must be in regular expression format + * @return + */ + public static String getLastToken(String input, String token) + { + if (input == null) + { + return null; + } + if (token == null) + { + return input; + } + String[] st = input.split(token); + return st[st.length - 1]; + } + + /** * Parses the input string into components separated by the delimiter. Unlike * String.split(), this method will ignore occurrences of the delimiter which * are nested within single quotes in name-value pair values, e.g. a='b,c'. @@ -390,7 +413,8 @@ public class StringUtils { return s.toUpperCase(Locale.ROOT); } - return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1).toLowerCase(Locale.ROOT); + return s.substring(0, 1).toUpperCase(Locale.ROOT) + + s.substring(1).toLowerCase(Locale.ROOT); } /** @@ -435,8 +459,8 @@ public class StringUtils } /** - * Answers the input string with any occurrences of the 'encodeable' characters - * replaced by their URL encoding + * Answers the input string with any occurrences of the 'encodeable' + * characters replaced by their URL encoding * * @param s * @param encodable @@ -572,4 +596,18 @@ public class StringUtils } return true; } + + public static int firstCharPosIgnoreCase(String text, String chars) + { + int min = text.length() + 1; + for (char c : chars.toLowerCase(Locale.ROOT).toCharArray()) + { + int i = text.toLowerCase(Locale.ROOT).indexOf(c); + if (0 <= i && i < min) + { + min = i; + } + } + return min < text.length() + 1 ? min : -1; + } }