Package com.adobe.xfa.ut
Class StringUtils
- java.lang.Object
-
- com.adobe.xfa.ut.StringUtils
-
public final class StringUtils extends Object
This class provides some utility methods that were available in jfString, but are not part of the Java String interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StringUtils.ToXMLType
-
Field Summary
Fields Modifier and Type Field Description static Comparator<String>
CASE_INSENSITIVE_COMPARATOR
Publicly available case-insensitive comparator.static Comparator<String>
UCS_CODEPOINT_COMPARATOR
Compares Strings based on UCS codepoint values.static String
WHITE_SPACE
Set of characters considered to be white space.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
equalsWithNull(String s1, String s2)
General-purpose string equality comparison for strings that may be null.static int
findNoCase(CharSequence source, CharSequence target, int fromIndex)
Scan a string for a string, but ignore case.static Comparator<String>
getCaseInsensitiveComparator()
Return a comparator that performs case-insensitive string comparisons.static boolean
isEmpty(CharSequence s)
Empty string test.static Long
longNumber(String s)
static Long
longNumber(String s, int radix)
static Integer
number(String s)
static Integer
number(String s, int radix)
static String
parseToken(StringBuilder source)
static void
replace(StringBuilder buf, char find, char rep)
static void
replace(StringBuilder buf, char find, char rep, int start, int limit)
static long
safeLongNumber(String s)
static long
safeLongNumber(String s, int radix)
static int
safeNumber(String s)
static int
safeNumber(String s, int radix)
static int
skipOver(CharSequence src, String sSkip, int nOffset)
Scan this string for the first character not in the given set.static int
skipUntil(CharSequence src, String sSkip, int nOffset)
Scan this string for the first character in the given set.static String
toXHTML(String sSrc, boolean bIncludePI)
Replaces specified characters in the current string with their entity references.static String
toXML(String src, boolean isAttribute)
static String
toXML(String sSrc, StringUtils.ToXMLType eTargetType, String sOthers, char cRangeMin, char cRangeMax, String sExclude)
Replaces specified characters in the current string with their entity references.static String
trim(String s)
static void
trim(StringBuilder buf)
Remove white space from the end of a string buffer.static String
trimStart(String s)
static void
trimStart(StringBuilder buf)
Remove white space from the start of a string buffer.
-
-
-
Field Detail
-
CASE_INSENSITIVE_COMPARATOR
public static final Comparator<String> CASE_INSENSITIVE_COMPARATOR
Publicly available case-insensitive comparator. You can also use the static method getCaseInsensitiveComparator() to get one.
-
UCS_CODEPOINT_COMPARATOR
public static final Comparator<String> UCS_CODEPOINT_COMPARATOR
Compares Strings based on UCS codepoint values.
-
WHITE_SPACE
public static final String WHITE_SPACE
Set of characters considered to be white space.- See Also:
- Constant Field Values
-
-
Method Detail
-
equalsWithNull
public static boolean equalsWithNull(String s1, String s2)
General-purpose string equality comparison for strings that may be null. This method compares two strings for equality, allowing for possible null references and non-interned strings.- Parameters:
s1
- First string to compare.s2
- First string to compare.- Returns:
- True if the strings are equal; false if not. Note that two null references would be considered equal.
-
findNoCase
public static int findNoCase(CharSequence source, CharSequence target, int fromIndex)
Scan a string for a string, but ignore case. The only ASCII case folding is considered. Comparisons are done on a character by character basis (i.e., Unicode not code points are not considered).- Parameters:
source
- the string being searched.target
- the string to search for.fromIndex
- the index to begin searching from.- Returns:
- the start position for where the string was found. If the string was not found, -1.
-
getCaseInsensitiveComparator
public static Comparator<String> getCaseInsensitiveComparator()
Return a comparator that performs case-insensitive string comparisons.- Returns:
- A comparator that performs case insensitive comparisons.
-
isEmpty
public static boolean isEmpty(CharSequence s)
Empty string test. Short-hand to test a string for null pointer or empty condition.- Parameters:
s
- String to be tested.- Returns:
- True if the given string reference is null or empty; false otherwise.
-
parseToken
public static String parseToken(StringBuilder source)
-
replace
public static void replace(StringBuilder buf, char find, char rep)
-
replace
public static void replace(StringBuilder buf, char find, char rep, int start, int limit)
-
safeNumber
public static int safeNumber(String s)
-
safeNumber
public static int safeNumber(String s, int radix)
-
safeLongNumber
public static long safeLongNumber(String s)
-
safeLongNumber
public static long safeLongNumber(String s, int radix)
-
skipOver
public static int skipOver(CharSequence src, String sSkip, int nOffset)
Scan this string for the first character not in the given set. Similar to strspn().- Parameters:
sSkip
- - the characters to scan fornOffset
- - the position where to start the scan. Default = 0- Returns:
- The position, relative to nOffset, for the first character not found in the given set
-
skipUntil
public static int skipUntil(CharSequence src, String sSkip, int nOffset)
Scan this string for the first character in the given set. Similar to strcspn().- Parameters:
src
- - the string to scansSkip
- - the characters to scan fornOffset
- - the position where to start the scan. Default = 0.- Returns:
- The position, relative to nOffset, for the first character found in the given set
-
trim
public static void trim(StringBuilder buf)
Remove white space from the end of a string buffer.- Parameters:
buf
- - String buffer to be trimmed.
-
trimStart
public static void trimStart(StringBuilder buf)
Remove white space from the start of a string buffer.- Parameters:
buf
- - String buffer to be trimmed.
-
toXML
public static String toXML(String sSrc, StringUtils.ToXMLType eTargetType, String sOthers, char cRangeMin, char cRangeMax, String sExclude)
Replaces specified characters in the current string with their entity references.'&' is replaced with "&" '<' is replaced with "<" if eTargetType = XMLTEXT '>' is replaced with ">" if eTargetType = XMLATTRIBUTE_WITH_DQUOTE '"' is replaced with """ if eTargetType = XMLATTRIBUTE_WITH_QUOTE ''' is replaced with "'"
Any characters found in sOthers are replaced with entity references. Any characters found inbetween and including the cRangeStart and cRangeEnd are replaced with entity references.- Parameters:
sSrc
- the source string.eTargetType
- an enum indicating the target xml type.sOthers
- a list of characters to be encoded in this string.cRangeMin
- Any characters greater than or equal to this char are encoded with their entity references.cRangeMax
- Any characters less than or equal to this char are encoded with their entity references.sExclude
- a list of characters NOT to be encoded in this string.- Returns:
- The converted string.
-
toXHTML
public static String toXHTML(String sSrc, boolean bIncludePI)
Replaces specified characters in the current string with their entity references. and wraps the text in andelements.
'&' is replaced with "&" '<' is replaced with "<" '>' is replaced with ">"
All line feeds are are replaced with
.- Parameters:
sSrc
- the source string.bIncludePI
- true if the string should be prefixed with .- Returns:
- The converted string.
-
-