Merge branch 'benreview/JAL-3691_for_2_11_2_getdownrebuilds' into develop
[jalview.git] / src / jalview / util / StringUtils.java
index 1f114a8..ff1c944 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.util;
 
+import java.util.Locale;
+
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
@@ -409,9 +411,9 @@ public class StringUtils
     }
     if (s.length() <= 1)
     {
-      return s.toUpperCase();
+      return s.toUpperCase(Locale.ROOT);
     }
-    return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
+    return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1).toLowerCase(Locale.ROOT);
   }
 
   /**
@@ -427,7 +429,7 @@ public class StringUtils
     {
       return null;
     }
-    String tmp2up = text.toUpperCase();
+    String tmp2up = text.toUpperCase(Locale.ROOT);
     int startTag = tmp2up.indexOf("<HTML>");
     if (startTag > -1)
     {
@@ -446,7 +448,7 @@ public class StringUtils
     {
       text = text.substring(0, endTag);
     }
-  
+
     if (startTag == -1 && (text.contains("<") || text.contains(">")))
     {
       text = text.replaceAll("<", "&lt;");
@@ -456,8 +458,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
@@ -568,4 +570,18 @@ public class StringUtils
     }
     return enc;
   }
+
+  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;
+  }
 }