From: Ben Soares Date: Tue, 31 Oct 2023 09:28:36 +0000 (+0000) Subject: JAL-4059 Converting Pattern/Matcher methods that are possibly incompatible with JS... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3b65a96203737c2ace58b1205e0056508e9dbff3;p=jalview.git JAL-4059 Converting Pattern/Matcher methods that are possibly incompatible with JS regex equivalents --- diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java index 89bc36d..9212c8e 100644 --- a/src/jalview/util/StringUtils.java +++ b/src/jalview/util/StringUtils.java @@ -25,7 +25,6 @@ import java.net.URLEncoder; 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 @@ -178,6 +177,8 @@ 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()) @@ -597,14 +598,20 @@ public class StringUtils 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) + { + return -1; + } + for (int i = 0; i < text.length(); i++) { - index = m.start(); + if (Character.isWhitespace(text.charAt(i))) + { + return i; + } } - return index; + return -1; } /*