Class LocationCodePointSource<D>
- Type Parameters:
D- the type of document identifiers
- All Implemented Interfaces:
CodePointSource,IntSupplier
Code points are obtained from another code point source. For the consistency of the computed location information, it is required that there are no other, concurrent consumers of code points from that source.
For tracking line and column number information, the following
ISO control characters are recognized:
'\n' not preceded by a '\r'
advances the line number and resets the column number.
'\r' and the sequence "\r\n" are normalized
to '\n' and do the same.
This corresponds to the behaviour of LineNumberReader.
'\f' is delivered as a normal character.
This is required for processing Java source texts, see
language specification.
'\t' advances the column number to the next tab stop.
Tab stops are set at multiples of the given tabWidth.
Other ISO "group zero" control
characters must not occur among the input code points, or a LocationCodePointException is thrown.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default width of tab stops. -
Constructor Summary
ConstructorsConstructorDescriptionLocationCodePointSource(CodePointSource input, D documentId, int firstLine, int firstColumn) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidRecords the end of the current interval as the beginning of the next.intgetAsInt()Returns the next code point if available.Returns a location corresponding to the beginning of the current interval.Returns a location that spans the interval between the previously recorded begining and end points.Returns a location corresponding to the end of the current interval.Returns a location that spans the interval between the previously recorded begin point and the current position.getPoint()Returns a location that points to the current input position.voidRecords the current input position as the beginning of an interval.voidRecords the current input position as the end of an interval.voidsetTabWidth(int tabWidth) Sets the width of tab stops.
-
Field Details
-
DEFAULT_TAB_WIDTH
public static final int DEFAULT_TAB_WIDTHThe default width of tab stops. The value is1, such that tabs count as single spaces.- See Also:
-
-
Constructor Details
-
LocationCodePointSource
public LocationCodePointSource(CodePointSource input, @Opt D documentId, int firstLine, int firstColumn) Creates a new instance.- Parameters:
input- the input code point sourcedocumentId- the identifier of the underlying document, ornullif not availablefirstLine- the non-negative first line number of the underlying document, or one of the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLEfirstColumn- the non-negative first column number of each line of the underlying document, or one of the special valuesLocation.UNKNOWNorLocation.NOT_APPLICABLE- See Also:
-
-
Method Details
-
getPoint
Returns a location that points to the current input position.- Returns:
- a location that points to the current input position
-
setBeginPoint
public void setBeginPoint()Records the current input position as the beginning of an interval.- See Also:
-
setEndPoint
public void setEndPoint()Records the current input position as the end of an interval.- See Also:
-
advancePoint
public void advancePoint()Records the end of the current interval as the beginning of the next.- See Also:
-
getBeginPoint
Returns a location corresponding to the beginning of the current interval.The result is unspecified if
setBeginPoint()has not been called.- Returns:
- a location corresponding to the beginning of the current interval
- See Also:
-
getEndPoint
Returns a location corresponding to the end of the current interval.The result is unspecified if
setEndPoint()has not been called.- Returns:
- a location corresponding to the end of the current interval
- See Also:
-
getClosedRegion
Returns a location that spans the interval between the previously recorded begining and end points.- Returns:
- a location that spans the interval between the previously recorded begining and end points
- See Also:
-
getOpenRegion
Returns a location that spans the interval between the previously recorded begin point and the current position.- Returns:
- a location that spans the interval between the previously recorded begin point and the current position
- See Also:
-
getAsInt
public int getAsInt()Returns the next code point if available. Unifies the different CR/LF-strategies: returns "\n" for "\r" and "\r\n".- Specified by:
getAsIntin interfaceCodePointSource- Specified by:
getAsIntin interfaceIntSupplier- Returns:
- either a valid Unicode code point, or
-1to indicate that the end of the stream has been reached - Throws:
LocationCodePointException- if a code point is encountered that denotes any ISO control character other than the recognized ones- See Also:
-
setTabWidth
public void setTabWidth(int tabWidth) Sets the width of tab stops.- Parameters:
tabWidth- the new width of tab stops- Throws:
IllegalArgumentException- if the given width is non-positive
-