@Beta public final class TextUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
TextUtil.SuspiciousValueLogger
Interface you can i
|
| Modifier and Type | Field and Description |
|---|---|
static int |
MIN_GACK_LENGTH |
| Constructor and Description |
|---|
TextUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
breakLongWordsAndEscapeToHTML(String text,
boolean preserveNewLinesInHtml)
Break long words and escape markup to HTML.
|
static String |
breakLongWordsAndEscapeToHTML(String text,
boolean preserveNewLinesInHtml,
int maxWordLength)
Break long words and escape markup to HTML.
|
static String |
escapeForMessageFormat(String str) |
static StringBuilder |
escapeForMessageFormat(String src,
StringBuilder sb,
boolean check)
Single-quotes and curly brackets are special characters used by Java's MessageFormat class.
|
static String |
escapeToHtml(String value)
Escape output being sent to the user to be safe in HTML.
|
static String |
escapeToHtml(String value,
boolean escapeNewline)
Escape output being sent to the user to be safe in HTML.
|
static String |
escapeToXml(CharSequence input)
Escapes
Strings into valid xml. |
static String |
escapeToXml(CharSequence input,
boolean allowNewLines,
boolean convertNulls) |
static String |
escapeToXml(CharSequence input,
boolean allowNewLines,
boolean convertNulls,
boolean escapeApos) |
static String |
escapeToXml(CharSequence input,
boolean allowNewLines,
boolean convertNulls,
boolean escapeApos,
boolean preserveWhitespace)
Escapes
Strings into valid xml. |
static Comparator<String> |
getComparator(Collator collator,
int size) |
static String |
initCap(String in)
Makes the first letter of the input string upper case.
|
static boolean |
isEmptyOrWhitespace(CharSequence str) |
static boolean |
isIsoControlOrOddUnicode(char c)
Determines if the given input char is an iso-control character, undefined, or in an unusable Unicode block.
|
static boolean |
isNullEmptyOrWhitespace(CharSequence str) |
static String |
join(String separator,
Object... objects)
Concatenate the string values of zero or more objects.
|
static String |
join(String separator,
String... strings)
Concatenate the string values of zero or more strings.
|
protected static void |
logValue(String source,
CharSequence value) |
static List<String> |
splitSimple(String delimiter,
String str)
Splits the given string str using the given delimiter and returns the result as a string list.
|
static List<String> |
splitSimple(String delimiter,
String str,
int expectedSize)
Splits the given string str using the given delimiter and returns the result as a string list.
|
static List<String> |
splitSimpleAndTrim(String str,
String delimiter,
int expectedSize)
Splits the given string str using the given delimiter, trims each element, and returns the result as a string
list.
|
static String |
trim(String str) |
public static final int MIN_GACK_LENGTH
protected static void logValue(String source, CharSequence value)
public static String escapeToXml(CharSequence input)
Strings into valid xml. Similar to escapeInput except that it will also
replace control characters with spaces.
public static String escapeToXml(CharSequence input, boolean allowNewLines, boolean convertNulls)
public static String escapeToXml(CharSequence input, boolean allowNewLines, boolean convertNulls, boolean escapeApos)
public static String escapeToXml(CharSequence input, boolean allowNewLines, boolean convertNulls, boolean escapeApos, boolean preserveWhitespace)
Strings into valid xml. Similar to escapeInput except that it will also
replace control characters with spaces.
input - the text to escapeallowNewLines - if false, newlines (\r or \n) are converted to spaces insteadconvertNulls - convert nulls to the empty string if treuescapeApos - Add a backslash in front of apostrophes to deal with MSXML's nonsensepreserveWhitespace - if true, whitespace chars (as defined by Character.isWhitespace(char)) are not converted to
spaces. If false, they may be converted to spaces if they are control characters. This argument is weaker
than allowNewLines, so if allowNewLines is true but this argument is false, newlines will
be preserved anyway. Since newlines are also whitespace, if allowNewLines is false but this
argument is true, then newlines will still be preserved.public static boolean isIsoControlOrOddUnicode(char c)
public static String escapeToHtml(String value)
public static String escapeToHtml(String value, boolean escapeNewline)
escapeNewline is true.
public static String trim(String str)
java.lang.String.trim(), which only trims characters before '\u0020'
but not characters like the wide space character in Japanese ('\u3000'). will return
an empty String if the input String is all whitespacepublic static boolean isNullEmptyOrWhitespace(CharSequence str)
public static boolean isEmptyOrWhitespace(CharSequence str)
public static List<String> splitSimple(String delimiter, String str)
delimiter - The delimiter to split the string usingstr - The string to splitpublic static List<String> splitSimple(String delimiter, String str, int expectedSize)
delimiter - The delimiter to split the string usingstr - The string to splitexpectedSize - The expected number of elements in the output list. If you don't know, or if it could be arbitrarily
large, and if you will only access the returned list sequentially with an iterator, then use 0 to tell
this method to use a LinkedListpublic static List<String> splitSimpleAndTrim(String str, String delimiter, int expectedSize)
str - The string to splitdelimiter - The delimiter to split the string usingexpectedSize - The expected number of elements in the output list. If you don't know, or if it could be arbitrarily
large, and if you will only access the returned list sequentially with an iterator, then use 0 to tell
this method to use a LinkedListpublic static String initCap(String in)
public static StringBuilder escapeForMessageFormat(String src, StringBuilder sb, boolean check)
public static String breakLongWordsAndEscapeToHTML(String text, boolean preserveNewLinesInHtml)
text - the text to break and escapepreserveNewLinesInHtml - whether to preserve new line characters (\n) as public static String breakLongWordsAndEscapeToHTML(String text, boolean preserveNewLinesInHtml, int maxWordLength)
text - the text to break and escapepreserveNewLinesInHtml - whether to preserve new line characters (\n) as maxWordLength - words longer than this will be broken with public static String join(String separator, String... strings)
separator - - string that will delimit the result.strings - - the strings whose values will be concatenatedpublic static String join(String separator, Object... objects)
separator - - string that will delimit the result.objects - - the objects whose string values will be concatenatedpublic static Comparator<String> getComparator(Collator collator, int size)
the - number of elements to compare (default is 16).Copyright (c) 2016-2017, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE.txt file in the repository.