net.sf.saxon.value
Class Whitespace
java.lang.Object
net.sf.saxon.value.Whitespace
public class Whitespace
extends java.lang.Object
This class provides helper methods and constants for handling whitespace
static int | ALL
|
static int | COLLAPSE
|
static int | IGNORABLE
|
static int | NONE - The values NONE, IGNORABLE, and ALL identify which kinds of whitespace text node
should be stripped when building a source tree.
|
static int | PRESERVE - The values PRESERVE, REPLACE, and COLLAPSE represent the three options for whitespace
normalization.
|
static int | REPLACE
|
static int | UNSPECIFIED
|
static int | XSLT
|
static CharSequence | applyWhitespaceNormalization(int action, CharSequence value) - Apply schema-defined whitespace normalization to a string
|
static CharSequence | collapseWhitespace(CharSequence in) - Collapse whitespace as defined in XML Schema.
|
static boolean | containsWhitespace(CharSequence value) - Determine if a string contains any whitespace
|
static boolean | isWhite(CharSequence content) - Determine if a string is all-whitespace
|
static boolean | isWhitespace(int ch) - Test whether a character is whitespace
|
static CharSequence | normalizeWhitespace(CharSequence in) - Normalize whitespace as defined in XML Schema.
|
static CharSequence | removeAllWhitespace(CharSequence value) - Remove all whitespace characters from a string
|
static CharSequence | removeLeadingWhitespace(CharSequence value) - Remove leading whitespace characters from a string
|
static String | trim(CharSequence s) - Trim leading and trailing whitespace from a string, returning a string.
|
static CharSequence | trimWhitespace(CharSequence in) - Remove leading and trailing whitespace.
|
ALL
public static final int ALL
COLLAPSE
public static final int COLLAPSE
IGNORABLE
public static final int IGNORABLE
NONE
public static final int NONE
The values NONE, IGNORABLE, and ALL identify which kinds of whitespace text node
should be stripped when building a source tree. UNSPECIFIED indicates that no
particular request has been made. XSLT indicates that whitespace should be stripped
as defined by the xsl:strip-space and xsl:preserve-space declarations in the stylesheet
PRESERVE
public static final int PRESERVE
The values PRESERVE, REPLACE, and COLLAPSE represent the three options for whitespace
normalization. They are deliberately chosen in ascending strength order; given a number
of whitespace facets, only the strongest needs to be carried out.
REPLACE
public static final int REPLACE
UNSPECIFIED
public static final int UNSPECIFIED
XSLT
public static final int XSLT
applyWhitespaceNormalization
public static CharSequence applyWhitespaceNormalization(int action,
CharSequence value)
Apply schema-defined whitespace normalization to a string
action
- the action to be applied: one of PRESERVE, REPLACE, or COLLAPSEvalue
- the value to be normalized
- the value after normalization
collapseWhitespace
public static CharSequence collapseWhitespace(CharSequence in)
Collapse whitespace as defined in XML Schema. This is equivalent to the
XPath normalize-space() function
in
- the string whose whitespace is to be collapsed
- the string with any leading or trailing whitespace removed, and any
internal sequence of whitespace characters replaced with a single space character.
containsWhitespace
public static boolean containsWhitespace(CharSequence value)
Determine if a string contains any whitespace
value
- the string to be tested
- true if the string contains a character that is XML whitespace, that is
tab, newline, carriage return, or space
isWhite
public static boolean isWhite(CharSequence content)
Determine if a string is all-whitespace
content
- the string to be tested
- true if the supplied string contains no non-whitespace
characters
isWhitespace
public static boolean isWhitespace(int ch)
Test whether a character is whitespace
ch
- the character (Unicode codepoint) to be tested
- true if the character is one of tab, newline, carriage return, or space
normalizeWhitespace
public static CharSequence normalizeWhitespace(CharSequence in)
Normalize whitespace as defined in XML Schema. Note that this is not the same
as the XPath normalize-space() function, which is supported by the
collapseWhitespace(CharSequence)
method
in
- the string to be normalized
- a copy of the string in which any whitespace character is replaced by
a single space character
removeAllWhitespace
public static CharSequence removeAllWhitespace(CharSequence value)
Remove all whitespace characters from a string
value
- the string from which whitespace is to be removed
- the string without its whitespace. This may be the original value
if it contained no whitespace
removeLeadingWhitespace
public static CharSequence removeLeadingWhitespace(CharSequence value)
Remove leading whitespace characters from a string
value
- the string whose leading whitespace is to be removed
- the string with leading whitespace removed. This may be the
original string if there was no leading whitespace
trim
public static String trim(CharSequence s)
Trim leading and trailing whitespace from a string, returning a string.
This differs from the Java trim() method in that the only characters treated as
whitespace are space, \n, \r, and \t. The String#trim() method removes all C0
control characters (which is not the same thing under XML 1.1).
s
- the string to be trimmed. If null is supplied, null is returned.
- the string with leading and trailing whitespace removed.
trimWhitespace
public static CharSequence trimWhitespace(CharSequence in)
Remove leading and trailing whitespace. This has the same effect as collapseWhitespace,
but is cheaper, for use by data types that do not allow internal whitespace.
in
- the input string whose whitespace is to be removed
- the result of removing excess whitespace