public final class StringUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.StringJoiner
A StringJoiner allows incremental / filtered joining of a set of stringable objects.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
controlChars |
private static java.util.regex.Pattern |
extraDotSegmentsPattern |
private static int |
MaxCachedBuilderSize |
private static int |
MaxIdleBuilders |
(package private) static java.lang.String[] |
padding |
private static java.lang.ThreadLocal<java.util.Stack<java.lang.StringBuilder>> |
threadLocalBuilders |
private static java.util.regex.Pattern |
validUriScheme |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
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.
|
static java.lang.StringBuilder |
borrowBuilder()
Maintains cached StringBuilders in a flyweight pattern, to minimize new StringBuilder GCs.
|
static boolean |
in(java.lang.String needle,
java.lang.String... haystack) |
static boolean |
inSorted(java.lang.String needle,
java.lang.String[] haystack) |
static boolean |
isActuallyWhitespace(int c)
Tests if a code point is "whitespace" as defined by what it looks like.
|
static boolean |
isAscii(java.lang.String string)
Tests that a String contains only ASCII characters.
|
static boolean |
isBlank(java.lang.String string)
Tests if a string is blank: null, empty, or only whitespace (" ", \r\n, \t, etc)
|
static boolean |
isInvisibleChar(int c) |
static boolean |
isNumeric(java.lang.String string)
Tests if a string is numeric, i.e.
|
static boolean |
isWhitespace(int c)
Tests if a code point is "whitespace" as defined in the HTML spec.
|
static java.lang.String |
join(java.util.Collection<?> strings,
java.lang.String sep)
Join a collection of strings by a separator
|
static java.lang.String |
join(java.util.Iterator<?> strings,
java.lang.String sep)
Join a collection of strings by a separator
|
static java.lang.String |
join(java.lang.String[] strings,
java.lang.String sep)
Join an array of strings by a separator
|
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.
|
static java.lang.String |
padding(int width)
Returns space padding (up to the default max of 30).
|
static java.lang.String |
padding(int width,
int maxPaddingWidth)
Returns space padding, up to a max of maxPaddingWidth.
|
static java.lang.String |
releaseBuilder(java.lang.StringBuilder sb)
Release a borrowed builder.
|
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.
|
static java.net.URL |
resolve(java.net.URL base,
java.lang.String relUrl)
Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
|
static boolean |
startsWithNewline(java.lang.String string)
Tests if a string starts with a newline character
|
private static java.lang.String |
stripControlChars(java.lang.String input) |
static final java.lang.String[] padding
private static final java.util.regex.Pattern extraDotSegmentsPattern
private static final java.util.regex.Pattern validUriScheme
private static final java.util.regex.Pattern controlChars
private static final java.lang.ThreadLocal<java.util.Stack<java.lang.StringBuilder>> threadLocalBuilders
private static final int MaxCachedBuilderSize
private static final int MaxIdleBuilders
public static java.lang.String join(java.util.Collection<?> strings, java.lang.String sep)
strings
- collection of string objectssep
- string to place between stringspublic static java.lang.String join(java.util.Iterator<?> strings, java.lang.String sep)
strings
- iterator of string objectssep
- string to place between stringspublic static java.lang.String join(java.lang.String[] strings, java.lang.String sep)
strings
- collection of string objectssep
- string to place between stringspublic static java.lang.String padding(int width)
padding(int, int)
to specify a different limit.width
- amount of padding desiredpadding(int, int)
public static java.lang.String padding(int width, int maxPaddingWidth)
width
- amount of padding desiredmaxPaddingWidth
- maximum padding to apply. Set to -1
for unlimited.public static boolean isBlank(java.lang.String string)
string
- string to testpublic static boolean startsWithNewline(java.lang.String string)
string
- string to testpublic static boolean isNumeric(java.lang.String string)
string
- string to testpublic static boolean isWhitespace(int c)
c
- code point to testisActuallyWhitespace(int)
public static boolean isActuallyWhitespace(int c)
c
- code point to testpublic static boolean isInvisibleChar(int c)
public static java.lang.String normaliseWhitespace(java.lang.String string)
string
- content to normalisepublic static void appendNormalisedWhitespace(java.lang.StringBuilder accum, java.lang.String string, boolean stripLeading)
accum
- builder to append tostring
- string to normalize whitespace withinstripLeading
- set to true if you wish to remove any leading whitespacepublic static boolean in(java.lang.String needle, java.lang.String... haystack)
public static boolean inSorted(java.lang.String needle, java.lang.String[] haystack)
public static boolean isAscii(java.lang.String string)
string
- scanned stringpublic static java.net.URL resolve(java.net.URL base, java.lang.String relUrl) throws java.net.MalformedURLException
base
- the existing absolute base URLrelUrl
- the relative URL to resolve. (If it's already absolute, it will be returned)java.net.MalformedURLException
- if an error occurred generating the URLpublic static java.lang.String resolve(java.lang.String baseUrl, java.lang.String relUrl)
baseUrl
- the existing absolute base URLrelUrl
- the relative URL to resolve. (If it's already absolute, it will be returned)private static java.lang.String stripControlChars(java.lang.String input)
public static java.lang.StringBuilder borrowBuilder()
Care must be taken to release the builder once its work has been completed, with releaseBuilder(java.lang.StringBuilder)
public static java.lang.String releaseBuilder(java.lang.StringBuilder sb)
sb
- the StringBuilder to release.