Package net.sf.saxon.tree.tiny
Class CompressedWhitespace
java.lang.Object
net.sf.saxon.tree.tiny.CompressedWhitespace
- All Implemented Interfaces:
CharSequence
This class provides a compressed representation of a sequence of whitespace characters. The representation
is a sequence of bytes: in each byte the top two bits indicate which whitespace character is used
(x9, xA, xD, or x20) and the bottom six bits indicate the number of such characters. A zero byte is a filler.
We don't compress the sequence if it would occupy more than 8 bytes, because that's the space we've got available
in the TinyTree arrays.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) Returns thecharvalue at the specified index.static CharSequencecompress(CharSequence in) Attempt to compress a CharSequencebooleanIndicates whether some other object is "equal to" this one.longinthashCode()Returns a hash code value for the object.intlength()subSequence(int start, int end) Returns a newCharSequencethat is a subsequence of this sequence.toString()Returns a string representation of the object.static voiduncompress(long value, FastStringBuffer buffer) uncompress(FastStringBuffer buffer) Uncompress the whitespace to a FastStringBuffervoidWrite the value to a WritervoidwriteEscape(boolean[] specialChars, Writer writer) Write the value to a Writer with escaping of special charactersMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Constructor Details
-
CompressedWhitespace
public CompressedWhitespace(long compressedValue)
-
-
Method Details
-
compress
Attempt to compress a CharSequence- Parameters:
in- the CharSequence to be compressed- Returns:
- the compressed sequence if it can be compressed; or the original CharSequence otherwise
-
uncompress
Uncompress the whitespace to a FastStringBuffer- Parameters:
buffer- the buffer to which the whitespace is to be appended. The parameter may be null, in which case a new buffer is created.- Returns:
- the FastStringBuffer to which the whitespace has been appended. If a buffer was supplied in the argument, this will be the same buffer.
-
uncompress
-
getCompressedValue
public long getCompressedValue() -
length
public int length()- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) Returns thecharvalue at the specified index. An index ranges from zero to length() - 1. The firstcharvalue of the sequence is at index zero, the next at index one, and so on, as for array indexing.If the
charvalue specified by the index is a surrogate, the surrogate value is returned.- Specified by:
charAtin interfaceCharSequence- Parameters:
index- the index of thecharvalue to be returned- Returns:
- the specified
charvalue - Throws:
IndexOutOfBoundsException- if the index argument is negative or not less than length()
-
subSequence
Returns a newCharSequencethat is a subsequence of this sequence. The subsequence starts with thecharvalue at the specified index and ends with thecharvalue at index end - 1. The length (inchars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.- Specified by:
subSequencein interfaceCharSequence- Parameters:
start- the start index, inclusiveend- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
IndexOutOfBoundsException- if start or end are negative, if end is greater than length(), or if start is greater than end
-
equals
Indicates whether some other object is "equal to" this one. -
hashCode
public int hashCode()Returns a hash code value for the object. -
toString
Returns a string representation of the object.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
write
Write the value to a Writer- 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- Parameters:
specialChars- identifies which characters are considered specialwriter- the writer to write to- Throws:
IOException- if an error occurs downstream
-