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 theCompressedWhitespaceclass, 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 intcodePointAt(long index)Returns the codepoint value at the specified index.IntIteratorcodePoints()Get an iterator over the code points present in the string.intgetNewlines()Get the number of newlines at the startintgetSpaces()Get 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 objectjava.lang.StringtoString()Returns a string representation of the object.UnicodeStringuncompress()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 characters-
Methods inherited from class net.sf.saxon.str.WhitespaceString
getWidth, indexOf, substring
-
Methods inherited from class net.sf.saxon.str.UnicodeString
asAtomic, checkSubstringBounds, compareTo, concat, economize, equals, estimatedLength, hashCode, hasSubstring, indexOf, indexOf, indexWhere, isEmpty, prefix, requireInt, 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:
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 to length() - 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:
java.lang.IndexOutOfBoundsException- if the index argument is negative or not less than length()
-
codePoints
public IntIterator 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
public java.lang.String toString()
Returns a string representation of the object.- Overrides:
toStringin classWhitespaceString
-
write
public void write(UnicodeWriter writer) throws java.io.IOException
Write the value to a UnicodeWriter- Specified by:
writein 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.IOExceptionWrite 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:
java.io.IOException- if an error occurs downstream
-
-