Package net.sf.saxon.str
Class IndentWhitespace
java.lang.Object
net.sf.saxon.str.UnicodeString
net.sf.saxon.str.WhitespaceString
net.sf.saxon.str.IndentWhitespace
- All Implemented Interfaces:
Comparable<UnicodeString>,AtomicMatchKey
This class provides a compressed representation of a string used to represent indentation: specifically,
an integer number of newlines followed by an integer number of spaces. It's a little cheaper than
the
CompressedWhitespace class, and is specifically used for constructing indentation and passing
it to a UTF8Writer, which recognizes it specially. Unlike CompressedWhitespace, it can't
handle arbitrary whitespace strings, only those consisting of newlines followed by spaces.-
Method Summary
Modifier and TypeMethodDescriptionintcodePointAt(long index) Returns the codepoint value at the specified index.Get an iterator over the code points present in the string.intGet the number of newlines at the startintGet the number of spaces following the newlineslonglength()Get the length of the stringintlength32()Get the length of the string, provided it is less than 2^31 charactersstatic IndentWhitespaceof(int newlines, int spaces) Create an IndentWhitespace objecttoString()Returns a string representation of the object.Uncompress the whitespace to a (normal) UnicodeStringvoidwrite(UnicodeWriter writer) Write the value to a UnicodeWritervoidwriteEscape(boolean[] specialChars, UnicodeWriter writer) Write the value to a Writer with escaping of special charactersMethods inherited from class net.sf.saxon.str.WhitespaceString
getWidth, indexOf, indexWhere, substringMethods inherited from class net.sf.saxon.str.UnicodeString
asAtomic, checkSubstringBounds, compareTo, concat, economize, equals, estimatedLength, hashCode, hasSubstring, indexOf, indexOf, isEmpty, prefix, requireInt, requireNonNegativeInt, substring, tidy, verifyCharacters
-
Method Details
-
of
Create an IndentWhitespace object- Parameters:
newlines- the number of newlines at the startspaces- the number of spaces following the newlines- Returns:
- the constructed (or potentially cached) IndentWhitespace object
-
uncompress
Uncompress the whitespace to a (normal) UnicodeString- Specified by:
uncompressin classWhitespaceString- Returns:
- the uncompressed value
-
length
public long length()Description copied from class:UnicodeStringGet the length of the string- Specified by:
lengthin classUnicodeString- Returns:
- the number of code points in the string
-
length32
public int length32()Description copied from class:UnicodeStringGet the length of the string, provided it is less than 2^31 characters- Overrides:
length32in classUnicodeString- Returns:
- the length of the string if it fits within a Java
int
-
getNewlines
public int getNewlines()Get the number of newlines at the start- Returns:
- the number of newline characters
-
getSpaces
public int getSpaces()Get the number of spaces following the newlines- Returns:
- the number of space characters
-
codePointAt
public int codePointAt(long index) Returns the codepoint value at the specified index. An index ranges from zero tolength() - 1. The first codepoint value of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Specified by:
codePointAtin classUnicodeString- Parameters:
index- the index of the codepoint value to be returned- Returns:
- the specified codepoint value
- Throws:
IndexOutOfBoundsException- if theindexargument is negative or not less thanlength()
-
codePoints
Description copied from class:UnicodeStringGet an iterator over the code points present in the string.- Specified by:
codePointsin classUnicodeString- Returns:
- an iterator that delivers the individual code points
-
toString
Returns a string representation of the object.- Overrides:
toStringin classWhitespaceString
-
write
Write the value to a UnicodeWriter- Specified by:
writein classWhitespaceString- Parameters:
writer- the writer to write to- Throws:
IOException- if an error occurs downstream
-
writeEscape
Write the value to a Writer with escaping of special characters- Specified by:
writeEscapein classWhitespaceString- Parameters:
specialChars- identifies which characters are considered specialwriter- the writer to write to- Throws:
IOException- if an error occurs downstream
-