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 TypeMethodDescriptionint
codePointAt
(long index) Returns the codepoint value at the specified index.Get an iterator over the code points present in the string.int
Get the number of newlines at the startint
Get the number of spaces following the newlineslong
length()
Get the length of the stringint
length32()
Get the length of the string, provided it is less than 2^31 charactersstatic IndentWhitespace
of
(int newlines, int spaces) Create an IndentWhitespace objecttoString()
Returns a string representation of the object.Uncompress the whitespace to a (normal) UnicodeStringvoid
write
(UnicodeWriter writer) Write the value to a UnicodeWritervoid
writeEscape
(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, substring
Methods 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:
uncompress
in classWhitespaceString
- Returns:
- the uncompressed value
-
length
public long length()Description copied from class:UnicodeString
Get the length of the string- Specified by:
length
in classUnicodeString
- Returns:
- the number of code points in the string
-
length32
public int length32()Description copied from class:UnicodeString
Get the length of the string, provided it is less than 2^31 characters- Overrides:
length32
in 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:
codePointAt
in classUnicodeString
- Parameters:
index
- the index of the codepoint value to be returned- Returns:
- the specified codepoint value
- Throws:
IndexOutOfBoundsException
- if theindex
argument is negative or not less thanlength()
-
codePoints
Description copied from class:UnicodeString
Get an iterator over the code points present in the string.- Specified by:
codePoints
in classUnicodeString
- Returns:
- an iterator that delivers the individual code points
-
toString
Returns a string representation of the object.- Overrides:
toString
in classWhitespaceString
-
write
Write the value to a UnicodeWriter- Specified by:
write
in 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:
writeEscape
in classWhitespaceString
- Parameters:
specialChars
- identifies which characters are considered specialwriter
- the writer to write to- Throws:
IOException
- if an error occurs downstream
-