Package org.jsoup.internal
Class StringUtil
- java.lang.Object
-
- org.jsoup.internal.StringUtil
-
public final class StringUtil extends java.lang.ObjectA minimal String utility class. Designed for internal jsoup use only.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Stack<java.lang.StringBuilder>buildersprivate static intMaxCachedBuilderSizeprivate static intMaxIdleBuilders(package private) static java.lang.String[]padding
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendNormalisedWhitespace(java.lang.StringBuilder accum, java.lang.String string, boolean stripLeading)After normalizing the whitespace within a string, appends it to a string builder.static java.lang.StringBuilderborrowBuilder()Maintains cached StringBuilders in a flyweight pattern, to minimize new StringBuilder GCs.static booleanin(java.lang.String needle, java.lang.String... haystack)static booleaninSorted(java.lang.String needle, java.lang.String[] haystack)static booleanisActuallyWhitespace(int c)Tests if a code point is "whitespace" as defined by what it looks like.static booleanisBlank(java.lang.String string)Tests if a string is blank: null, empty, or only whitespace (" ", \r\n, \t, etc)static booleanisInvisibleChar(int c)static booleanisNumeric(java.lang.String string)Tests if a string is numeric, i.e.static booleanisWhitespace(int c)Tests if a code point is "whitespace" as defined in the HTML spec.static java.lang.Stringjoin(java.lang.String[] strings, java.lang.String sep)Join an array of strings by a separatorstatic java.lang.Stringjoin(java.util.Collection strings, java.lang.String sep)Join a collection of strings by a separatorstatic java.lang.Stringjoin(java.util.Iterator strings, java.lang.String sep)Join a collection of strings by a separatorstatic java.lang.StringnormaliseWhitespace(java.lang.String string)Normalise the whitespace within this string; multiple spaces collapse to a single, and all whitespace characters (e.g.static java.lang.Stringpadding(int width)Returns space paddingstatic java.lang.StringreleaseBuilder(java.lang.StringBuilder sb)Release a borrowed builder.static java.lang.Stringresolve(java.lang.String baseUrl, java.lang.String relUrl)Create a new absolute URL, from a provided existing absolute URL and a relative URL component.static java.net.URLresolve(java.net.URL base, java.lang.String relUrl)Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
-
-
-
Field Detail
-
padding
static final java.lang.String[] padding
-
builders
private static final java.util.Stack<java.lang.StringBuilder> builders
-
MaxCachedBuilderSize
private static final int MaxCachedBuilderSize
- See Also:
- Constant Field Values
-
MaxIdleBuilders
private static final int MaxIdleBuilders
- See Also:
- Constant Field Values
-
-
Method Detail
-
join
public static java.lang.String join(java.util.Collection strings, java.lang.String sep)Join a collection of strings by a separator- Parameters:
strings- collection of string objectssep- string to place between strings- Returns:
- joined string
-
join
public static java.lang.String join(java.util.Iterator strings, java.lang.String sep)Join a collection of strings by a separator- Parameters:
strings- iterator of string objectssep- string to place between strings- Returns:
- joined string
-
join
public static java.lang.String join(java.lang.String[] strings, java.lang.String sep)Join an array of strings by a separator- Parameters:
strings- collection of string objectssep- string to place between strings- Returns:
- joined string
-
padding
public static java.lang.String padding(int width)
Returns space padding- Parameters:
width- amount of padding desired- Returns:
- string of spaces * width
-
isBlank
public static boolean isBlank(java.lang.String string)
Tests if a string is blank: null, empty, or only whitespace (" ", \r\n, \t, etc)- Parameters:
string- string to test- Returns:
- if string is blank
-
isNumeric
public static boolean isNumeric(java.lang.String string)
Tests if a string is numeric, i.e. contains only digit characters- Parameters:
string- string to test- Returns:
- true if only digit chars, false if empty or null or contains non-digit chars
-
isWhitespace
public static boolean isWhitespace(int c)
Tests if a code point is "whitespace" as defined in the HTML spec. Used for output HTML.- Parameters:
c- code point to test- Returns:
- true if code point is whitespace, false otherwise
- See Also:
isActuallyWhitespace(int)
-
isActuallyWhitespace
public static boolean isActuallyWhitespace(int c)
Tests if a code point is "whitespace" as defined by what it looks like. Used for Element.text etc.- Parameters:
c- code point to test- Returns:
- true if code point is whitespace, false otherwise
-
isInvisibleChar
public static boolean isInvisibleChar(int c)
-
normaliseWhitespace
public static java.lang.String normaliseWhitespace(java.lang.String string)
Normalise the whitespace within this string; multiple spaces collapse to a single, and all whitespace characters (e.g. newline, tab) convert to a simple space- Parameters:
string- content to normalise- Returns:
- normalised string
-
appendNormalisedWhitespace
public static void appendNormalisedWhitespace(java.lang.StringBuilder accum, java.lang.String string, boolean stripLeading)After normalizing the whitespace within a string, appends it to a string builder.- Parameters:
accum- builder to append tostring- string to normalize whitespace withinstripLeading- set to true if you wish to remove any leading whitespace
-
in
public static boolean in(java.lang.String needle, java.lang.String... haystack)
-
inSorted
public static boolean inSorted(java.lang.String needle, java.lang.String[] haystack)
-
resolve
public static java.net.URL resolve(java.net.URL base, java.lang.String relUrl) throws java.net.MalformedURLExceptionCreate a new absolute URL, from a provided existing absolute URL and a relative URL component.- Parameters:
base- the existing absolute base URLrelUrl- the relative URL to resolve. (If it's already absolute, it will be returned)- Returns:
- the resolved absolute URL
- Throws:
java.net.MalformedURLException- if an error occurred generating the URL
-
resolve
public static java.lang.String resolve(java.lang.String baseUrl, java.lang.String relUrl)Create a new absolute URL, from a provided existing absolute URL and a relative URL component.- Parameters:
baseUrl- the existing absolute base URLrelUrl- the relative URL to resolve. (If it's already absolute, it will be returned)- Returns:
- an absolute URL if one was able to be generated, or the empty string if not
-
borrowBuilder
public static java.lang.StringBuilder borrowBuilder()
Maintains cached StringBuilders in a flyweight pattern, to minimize new StringBuilder GCs. The StringBuilder is prevented from growing too large.Care must be taken to release the builder once its work has been completed, with
releaseBuilder(java.lang.StringBuilder)- Returns:
- an empty StringBuilder
-
releaseBuilder
public static java.lang.String releaseBuilder(java.lang.StringBuilder sb)
Release a borrowed builder. Care must be taken not to use the builder after it has been returned, as its contents may be changed by this method, or by a concurrent thread.- Parameters:
sb- the StringBuilder to release.- Returns:
- the string value of the released String Builder (as an incentive to release it!).
-
-