Package eu.bandm.tools.d2d2.infra
Class MemString<D>
java.lang.Object
eu.bandm.tools.d2d2.infra.MemString<D>
- Type Parameters:
D
- the document type used in locations. Sensible are String, File, XMLDocumentIdentifier, URI, etc.
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
MemScanner
Any memString is either one pointer (i.e. a position)
or two pointers (i.e. a range) into a range of memory filled
with character data, i.e. a
Line >= 0, Column == 0 is the first visible character in the line.
Line == 0,Column ==-1 means pointing to a non-existing char preceding ALL data.
Line > 0, Column == -1 means pointing to the LF-char ending the preceding line.
MemString.CharMem
.
It supports sequential access and maintains line and column counters
as follows:Line >= 0, Column == 0 is the first visible character in the line.
Line == 0,Column ==-1 means pointing to a non-existing char preceding ALL data.
Line > 0, Column == -1 means pointing to the LF-char ending the preceding line.
Currently this class is used as a base class for
MemScanner
.
CHAR_EOTEXT
is reserved for "end of data" indication. It must not be contained
in any method's arguments!
Most methods on this level do NOT test for "end of data", but rely on lower-level
access violation ("array index out of range", etc.) in case of overrun.
The responsibility to avoid these is by the caller.
MemStrings normally behave immutable, but for some methods there are
desctructive variants, the names of which end with an "X
"
The character "0x0A" is used "hard" for linefeed recognition.
For use with windows and Mac systems a LineNumberReader
is
inserted which does normalization to this character.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The data storage underlying everyMemString
.static class
Evidentclass
Used foraMemString.new Reader()
to use the memString as sequential character data source, e.g. -
Field Summary
Modifier and TypeFieldDescriptionstatic final char
Used to mark the end of valid character data.static final char
Used to mark the end of a line / start of a new line.protected int
protected MemString.CharMem<D>
The underlying data storage.protected int
protected int
protected int
-
Constructor Summary
ConstructorDescriptionCreates a newMemString.CharMem
store and creates a new MemString pointing to the first character in this data.MemString
(MemString.CharMem<D> mem) Creates a MemString pointing to the first character in the whole character data, as given by the charmMem.Creates a copy of the MemString argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Destructive variant: after advancement guaranteed not to CROSS a linefeed, (by any method which adds directly to pos and colnum) the fact of pointing TO a linefeed will be reflected in colnum/linenum.void
advanceByX_sameLine
(int i) Destructive variant: advance position and column number by the argument.void
advanceX()
Destructive variant: modifiesthis
to point one(1) character position behind its current position, and adjusts line and column number Does not test for overrun but maybe causes a lower-level error message.int
Append the character contents to the given StringBuilder.asString()
Return a String wich contains the character contents of this MemString.void
Destructive variant: modifiesthis
to point one(1) character position before its current position and adjusts line and column numbervoid
backwardsX
(int num) Destructive variant: modifiesthis
to point given characters position before its current position and adjusts line and column numberprotected void
Count distance to newline character backwards in data.clone()
Make shallow copy.boolean
boolean
boolean
Returns whether the lengths of this and the argument are the same, plusstartsWith(String)
.int
Return the current column number of the character contents, relative to the last preceding line-feed character in the underlying character memorydata
.get_data()
Return the underlying character memorydata
.int
get_len()
Return the current length of the character contents.int
Return the current line number of the character contents, relative to the underlying character memorydata
.int
Return the current start index of the character contents, relative to the underlying character memorydata
.char
getChar()
Get the first character of the contents.char
getChar
(int i) Get the character at position i of the contents.Returns a location of the position directly after this MemString.Returns a location with the field valueMemString.CharMem.originalAddress
and the line and column number.Returns a string containing blanks and one single "up-arrow" to indicate the current column optically.int
hashCode()
void
Re-sets all values of "this" to the values of the argument.boolean
startsWith
(String n) Returns what it says.toString()
Returns a diagnosis text which shows a representation of the underlyingMemString.CharMem
, the position, length, line and column number, and the first 10 characters.Returns a new MemString describing the range starting withthis
and ending before the argument.void
Limit the length of the character contents as destructive variant.
-
Field Details
-
CHAR_EOTEXT
public static final char CHAR_EOTEXTUsed to mark the end of valid character data.- See Also:
-
CHAR_NEWLINE
public static final char CHAR_NEWLINEUsed to mark the end of a line / start of a new line.- See Also:
-
data
The underlying data storage. The contents of the MemString is a sub-range of the data of that storage object. -
start
protected int start -
len
protected int len -
linenum
protected int linenum -
colnum
protected int colnum
-
-
Constructor Details
-
MemString
Creates a MemString pointing to the first character in the whole character data, as given by the charmMem. -
MemString
Creates a newMemString.CharMem
store and creates a new MemString pointing to the first character in this data.- Parameters:
id
- the name of the text, as used for diagnosis messages, etc.data
- the character contents copied into the memory.
-
MemString
Creates a copy of the MemString argument.
-
-
Method Details
-
asString
Return a String wich contains the character contents of this MemString. -
appendAll
Append the character contents to the given StringBuilder. -
getChar
public char getChar() -
getChar
public char getChar(int i) Get the character at position i of the contents. Is sensible only if0 <= i < len
. But may work without exception for other values, depnding on the state of the underlyingdata
. -
initFrom
Re-sets all values of "this" to the values of the argument. This is often a copy of a former state of "this", made byclone()
-
toString
Returns a diagnosis text which shows a representation of the underlyingMemString.CharMem
, the position, length, line and column number, and the first 10 characters. -
getLocation
Returns a location with the field valueMemString.CharMem.originalAddress
and the line and column number.Attention: these numbers are 1-(one)-based. They are one(1) bigger than the numbers stored internally and described above.
-
getFollowLocation
Returns a location of the position directly after this MemString. SeegetLocation()
for caveats. -
clone
Make shallow copy. Delegates toObject
. -
upTo
Returns a new MemString describing the range starting withthis
and ending before the argument.- Throws:
IllegalArgumentException
- when the underlying CharMem is not identical, or the argument is "left of"this
.
-
upToX
Limit the length of the character contents as destructive variant. Altersthis
to a region which ends directly before the argument.- Throws:
IllegalArgumentException
- when the underlying CharMem is not identical, or the argument is "left of"this
.
-
equals
Returns whether the lengths of this and the argument are the same, plusstartsWith(String)
. -
equals
-
equals
-
hashCode
public int hashCode() -
startsWith
Returns what it says. -
advanceByX_sameLine
public void advanceByX_sameLine(int i) Destructive variant: advance position and column number by the argument. Assume that no linefeed is crossed by this advancement. The new position may be a linefeed, which will lead to an adjustment. Currently only needed by MemScanner. The caller is responsible for avoiding overrun, i.e. may call it only when the next "count" characters have been identified as != CHAR_EOTEXT. -
adjustLineNumberX
public void adjustLineNumberX()Destructive variant: after advancement guaranteed not to CROSS a linefeed, (by any method which adds directly to pos and colnum) the fact of pointing TO a linefeed will be reflected in colnum/linenum. -
advanceX
public void advanceX()Destructive variant: modifiesthis
to point one(1) character position behind its current position, and adjusts line and column number Does not test for overrun but maybe causes a lower-level error message. The caller is responsible for avoiding this, i.e. call it only when the current character has been identified as != CHAR_EOTEXT. -
calccolnum
protected void calccolnum()Count distance to newline character backwards in data. Only needed bybackwardsX()
-
backwardsX
public void backwardsX()Destructive variant: modifiesthis
to point one(1) character position before its current position and adjusts line and column number -
backwardsX
public void backwardsX(int num) Destructive variant: modifiesthis
to point given characters position before its current position and adjusts line and column number -
get_len
public int get_len()Return the current length of the character contents. -
get_start
public int get_start()Return the current start index of the character contents, relative to the underlying character memorydata
. -
get_linenum
public int get_linenum()Return the current line number of the character contents, relative to the underlying character memorydata
. -
get_colnum
public int get_colnum()Return the current column number of the character contents, relative to the last preceding line-feed character in the underlying character memorydata
. -
get_data
Return the underlying character memorydata
. -
getPositionIndication
Returns a string containing blanks and one single "up-arrow" to indicate the current column optically.
-