public class ReaderLinesTracker
extends java.lang.Object
ReaderLinesTracker.Loc
.
Note that, in deference to XML locators, both lines and columns
(within documents and lines, respectively) are numbered from 1
rather than 0.
The primary motivation for the definition of this class is
to support the extraction of individual elements from an XML
document under the control of a SAX parser.
The public interface allows the back and front markers defining
the viewing window to be advanced, allows a segment to be extracted
from within the window, and allows a line within the window to be
searched for a given string.Constructor and Description |
---|
ReaderLinesTracker(java.io.File f)
Constructs a new tracker for the given file.
|
ReaderLinesTracker(java.io.Reader rdr)
Constructs a new tracker for the given reader.
|
Modifier and Type | Method and Description |
---|---|
void |
advanceBack(int lnlo,
int collo)
Advances this tracker's "back" marker to the location with the
specified line and column numbers.
|
void |
advanceFront(int lnhi,
int colhi)
Advances this tracker's front marker to the location with the
specified line and column numbers.
|
void |
close()
Closes this tracker along with the reader that backs it.
|
int |
findInLine(int i,
java.lang.String s)
Given the number of a line within this tracker's current viewing
window, and a search string, this method returns the column
number within the line of the specified line of (the first
occurrence of) the specified string, or
-1 if there are
no occurrences of the string in the line. |
int |
lnBack()
Returns the line number of this tracker's current back marker.
|
int |
lnFront()
Returns the line number of this tracker's current front marker.
|
java.lang.String[] |
segment(int lnlo,
int collo,
int lnhi,
int colhi)
Given the <line-no.,column-no.> pairs for the start and
finish locations of a segment within this tracker's current
viewing window, this method returns the specifed segment as
an array of strings, one per line or partial line.
|
public ReaderLinesTracker(java.io.Reader rdr) throws java.io.IOException
java.io.IOException
public ReaderLinesTracker(java.io.File f) throws java.io.IOException
java.io.IOException
public void close()
public int lnBack()
public int lnFront()
public void advanceBack(int lnlo, int collo)
public void advanceFront(int lnhi, int colhi)
public int findInLine(int i, java.lang.String s)
-1
if there are
no occurrences of the string in the line.public java.lang.String[] segment(int lnlo, int collo, int lnhi, int colhi)