diff options
Diffstat (limited to 'server/src/org/jsoup/helper/StringUtil.java')
-rw-r--r-- | server/src/org/jsoup/helper/StringUtil.java | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/server/src/org/jsoup/helper/StringUtil.java b/server/src/org/jsoup/helper/StringUtil.java index 071a92c7a5..5a3d19b0aa 100644 --- a/server/src/org/jsoup/helper/StringUtil.java +++ b/server/src/org/jsoup/helper/StringUtil.java @@ -8,12 +8,16 @@ import java.util.Iterator; */ public final class StringUtil { // memoised padding up to 10 - private static final String[] padding = {"", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}; + private static final String[] padding = { "", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " " }; /** * Join a collection of strings by a seperator - * @param strings collection of string objects - * @param sep string to place between strings + * + * @param strings + * collection of string objects + * @param sep + * string to place between strings * @return joined string */ public static String join(Collection strings, String sep) { @@ -22,17 +26,22 @@ public final class StringUtil { /** * Join a collection of strings by a seperator - * @param strings iterator of string objects - * @param sep string to place between strings + * + * @param strings + * iterator of string objects + * @param sep + * string to place between strings * @return joined string */ public static String join(Iterator strings, String sep) { - if (!strings.hasNext()) + if (!strings.hasNext()) { return ""; + } String start = strings.next().toString(); - if (!strings.hasNext()) // only one, avoid builder + if (!strings.hasNext()) { return start; + } StringBuilder sb = new StringBuilder(64).append(start); while (strings.hasNext()) { @@ -44,62 +53,79 @@ public final class StringUtil { /** * Returns space padding - * @param width amount of padding desired + * + * @param width + * amount of padding desired * @return string of spaces * width */ public static String padding(int width) { - if (width < 0) + if (width < 0) { throw new IllegalArgumentException("width must be > 0"); + } - if (width < padding.length) + if (width < padding.length) { return padding[width]; + } char[] out = new char[width]; - for (int i = 0; i < width; i++) + for (int i = 0; i < width; i++) { out[i] = ' '; + } return String.valueOf(out); } /** - * Tests if a string is blank: null, emtpy, or only whitespace (" ", \r\n, \t, etc) - * @param string string to test + * Tests if a string is blank: null, emtpy, or only whitespace (" ", \r\n, + * \t, etc) + * + * @param string + * string to test * @return if string is blank */ public static boolean isBlank(String string) { - if (string == null || string.length() == 0) + if (string == null || string.length() == 0) { return true; + } int l = string.length(); for (int i = 0; i < l; i++) { - if (!StringUtil.isWhitespace(string.codePointAt(i))) + if (!StringUtil.isWhitespace(string.codePointAt(i))) { return false; + } } return true; } /** * Tests if a string is numeric, i.e. contains only digit characters - * @param string string to test - * @return true if only digit chars, false if empty or null or contains non-digit chrs + * + * @param string + * string to test + * @return true if only digit chars, false if empty or null or contains + * non-digit chrs */ public static boolean isNumeric(String string) { - if (string == null || string.length() == 0) + if (string == null || string.length() == 0) { return false; + } int l = string.length(); for (int i = 0; i < l; i++) { - if (!Character.isDigit(string.codePointAt(i))) + if (!Character.isDigit(string.codePointAt(i))) { return false; + } } return true; } /** * Tests if a code point is "whitespace" as defined in the HTML spec. - * @param c code point to test + * + * @param c + * code point to test * @return true if code point is whitespace, false otherwise */ - public static boolean isWhitespace(int c){ + public static boolean isWhitespace(int c) { return c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r'; } @@ -117,12 +143,12 @@ public final class StringUtil { modified = true; continue; } - if (c != ' ') + if (c != ' ') { modified = true; + } sb.append(' '); lastWasWhite = true; - } - else { + } else { sb.appendCodePoint(c); lastWasWhite = false; } @@ -132,8 +158,9 @@ public final class StringUtil { public static boolean in(String needle, String... haystack) { for (String hay : haystack) { - if (hay.equals(needle)) - return true; + if (hay.equals(needle)) { + return true; + } } return false; } |