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:
java.lang.Comparable<UnicodeString>
,AtomicMatchKey
public class IndentWhitespace extends WhitespaceString
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 theCompressedWhitespace
class, and is specifically used for constructing indentation and passing it to aUTF8Writer
, which recognizes it specially. UnlikeCompressedWhitespace
, it can't handle arbitrary whitespace strings, only those consisting of newlines followed by spaces.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
codePointAt(long index)
Returns the codepoint value at the specified index.IntIterator
codePoints()
Get an iterator over the code points present in the string.int
getNewlines()
Get the number of newlines at the startint
getSpaces()
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 objectjava.lang.String
toString()
Returns a string representation of the object.UnicodeString
uncompress()
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 characters-
Methods 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 Detail
-
of
public static IndentWhitespace of(int newlines, int spaces)
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
public UnicodeString 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:
java.lang.IndexOutOfBoundsException
- if theindex
argument is negative or not less thanlength()
-
codePoints
public IntIterator 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
public java.lang.String toString()
Returns a string representation of the object.- Overrides:
toString
in classWhitespaceString
-
write
public void write(UnicodeWriter writer) throws java.io.IOException
Write the value to a UnicodeWriter- Specified by:
write
in classWhitespaceString
- Parameters:
writer
- the writer to write to- Throws:
java.io.IOException
- if an error occurs downstream
-
writeEscape
public void writeEscape(boolean[] specialChars, UnicodeWriter writer) throws java.io.IOException
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:
java.io.IOException
- if an error occurs downstream
-
-