public class StrUtils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ASCII_CHAR_RANGE |
static Pattern |
ASCII_CHARS_REGEX |
static int |
DEFAULT_STACK_LINES |
static int |
DEFAULT_TRUNCATE_LENGTH |
static String |
HTML_NEWLINE |
static String |
JS_NEWLINE |
static Pattern |
NORMALIZE_WHITE_SPACE_REGEX |
static Pattern |
NUMERIC_REGEX |
static String[] |
REGEX_SPECIAL_CHARS
Special characters within a regular expression.
|
static Pattern |
SIMPLE_NUMERIC_REGEX |
static Pattern |
STATEMENT_REGEX |
static Pattern |
STRIP_ASCII_REGEX |
static Pattern |
STRIP_PADDING |
static Pattern |
URL_BASE_REGEX |
Constructor and Description |
---|
StrUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
addWildcards(String string) |
static String |
dequote(String string)
Remove quotes surrounding a string.
|
static String |
escapeRegex(String regexSource)
Escape a string for use in a regular expression.
|
static String |
getAlternateCaseString(String string) |
static String |
getNice(String string) |
static String |
getNice(String string,
Boolean capitalize,
Boolean replaceUnderscore) |
static String |
getNonASCII(String string)
Get any and all characters that are not ASCII.
|
static String |
getNonNull(Object... objects) |
static Number |
getNumber(String string) |
static Number |
getNumber(String string,
Locale locale) |
static Number |
getNumberLoose(String string) |
static String |
getURIFilename(URI uri) |
static String |
getURLBase(String string)
Get the base of a url such that you have a url string to the same folder.
|
static String |
getURLFilename(String url) |
static String |
getURLFilename(URL url) |
static boolean |
isASCII(String string)
Test to see if string contains only ASCII characters.
|
static boolean |
isNumber(String string) |
static String |
normalize(String string)
Normalize a string by trimming and compacting whitespace.
|
static boolean |
nullOrEmpty(String string) |
static String |
safeJS(String string)
Scrub a String for things that make it unsuitable to insert into a
JavaScript string.
|
static String |
stripPadding(String string) |
static String |
toSeparatedString(List<?> list)
A generic comma separated string representation of a list.
|
static String |
toSeparatedString(Object[] array) |
static List<String> |
toStatements(String sql) |
static String |
toString(Exception e,
Boolean isJS) |
static String |
toString(Exception e,
Boolean isJS,
Integer lines)
Get a reasonable string representation of an exception.
|
static String |
toString(InputStream is) |
static String |
toString(List<?> list)
The default usage of
toString(List, Boolean) , outputting in
xhtml format. |
static String |
toString(List<?> list,
Boolean isJS)
A generic string representation of a list.
|
static String |
toString(Object object) |
static String |
toString(Object[] list) |
static String |
toString(Object[] list,
Boolean isJS) |
static String |
toString(String[] list,
Boolean isJS) |
static String |
toUpper(String string) |
static String |
truncate(String string)
Truncate a given string to a default length.
|
static String |
truncate(String string,
Integer length)
Truncate a given string to a provided length.
|
public static final int DEFAULT_TRUNCATE_LENGTH
public static final String JS_NEWLINE
public static final String HTML_NEWLINE
public static final int DEFAULT_STACK_LINES
public static final Pattern NORMALIZE_WHITE_SPACE_REGEX
public static final Pattern URL_BASE_REGEX
public static final String ASCII_CHAR_RANGE
public static final Pattern ASCII_CHARS_REGEX
public static final Pattern STRIP_ASCII_REGEX
public static final Pattern NUMERIC_REGEX
public static final Pattern SIMPLE_NUMERIC_REGEX
public static final Pattern STATEMENT_REGEX
public static final Pattern STRIP_PADDING
public static final String[] REGEX_SPECIAL_CHARS
escapeRegex(String)
public static String safeJS(String string)
Currently this only addresses non-escaped single quotes, double quotes and non-meaningful backslashes. Other issues will be addressed as discovered.
string
- - the string to be cleaned.public static String dequote(String string)
string
- - the string to remove surrounding quotes frompublic static String toString(List<?> list, Boolean isJS)
list
- - a list of objects with a usable toString() on each objectisJS
- - flag for whether the output is for javascript or xhtml
markuppublic static String toString(Exception e, Boolean isJS, Integer lines)
e
- - exception to convert to stringisJS
- - flag to indicate if you want javascript newlines or html
newlineslines
- - number of stacktrace lines to add to representationpublic static String toString(List<?> list)
toString(List, Boolean)
, outputting in
xhtml format.list
- - a list of objects with a usable toString() on each objectpublic static String toString(InputStream is) throws IOException
IOException
public static String escapeRegex(String regexSource)
regexSource
- - source string to escapeREGEX_SPECIAL_CHARS
public static String truncate(String string)
string
- - string to truncate if necessaryDEFAULT_TRUNCATE_LENGTH
,
truncate(String, Integer)
public static String truncate(String string, Integer length)
Note that the returned string may be longer than the specified length due to the addition of an elipses.
Note that truncate length is defaulted if null
string
- - string to truncate if necessarylength
- - length to truncate toDEFAULT_TRUNCATE_LENGTH
public static String normalize(String string)
string
- - string to normalizeNORMALIZE_WHITE_SPACE_REGEX
public static String getURLBase(String string)
Note that this requires the url string passed in to be a valid url. Typical usage is to get the base from the current URL. In that case, the url will always be valid.
string
- - url to get base of.URL_BASE_REGEX
public static boolean isASCII(String string)
Note that '^', '*' and '$' match the empty string in the regex and the single occurrence of the empty string token can't do triple duty. We return true for an empty string explicitly rather than using the regex.
string
- - string to test for non-ascii chars.ASCII_CHARS_REGEX
public static String getNonASCII(String string)
string
- - string to pull non-ASCII characters fromSTRIP_ASCII_REGEX
public static String toSeparatedString(List<?> list)
list
- - a list of objects with a usable toString() on each objectpublic static boolean isNumber(String string)
public static boolean nullOrEmpty(String string)
Copyright © 2019. All rights reserved.