SearchEngine class
Offers search and replace services in a text represented as list of lines. The service is only executed within in a region named currentRegion. Note: currentRegion can include the whole text (but does not have to be). The service starts at the currentPosition.
- Inheritance
-
- Object
- TextEngine
- SearchEngine
- Implementers
Constructors
-
SearchEngine(List<
String> lines, BaseLogger logger) -
The basic constructor defined by a text given as
lines
. - SearchEngine.fromString(String text, BaseLogger logger)
- This constructor defines the text given as single string.
Properties
- currentPosition ↔ Position
-
getter/setter pairinherited
- currentRegion ↔ Region
-
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastMatch ↔ LastMatch
-
the last hit found by a RegExpSearcher instance:
getter/setter pair
-
lines
↔ List<
String> -
getter/setter pairinherited
- logger ↔ BaseLogger
-
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tempPosition ↔ Position
-
getter/setter pairinherited
Methods
-
asList(
{required Position start, required Position end, bool isInclusive = false, List< String> ? list}) → List<String> -
Returns the text between two positions as a string list.
start
ist the position to start.end
is the the end of the wanted text. ifisInclusive
is trueend
is part of the returned text.inherited -
asString(
{required Position start, required Position end, bool isInclusive = false}) → String -
Returns the text between two positions as a string.
start
ist the position to start.end
is the the end of the wanted text. ifisInclusive
is trueend
is part of the returned text.inherited -
containsAt(
Position position, Searcher searcher) → bool -
Tests whether a given pattern matches the given
position
.searcher
defines the pattern. Returns true if thesearcher
is found atposition
-
count(
Searcher searcher, {int maximalHitsPerLine = 1, int? maximalHits, bool saveCurrentPosition = true}) → int -
Count the hits of a pattern from the current position to the
region end.
searcher
specifies the kind of search: regular expression, raw string... IfregExp
is not null this expression is searched. Ifpattern
is not null this string converted to a regular expression.maximalHitsPerLine
: if this count of hits is reached search is continued in the next line.maximalHits
: if this count is reached the search stops. Returns the number of hits. -
deleteFromTo(
{Position? start, required Position end}) → void -
Deletes the text between the positions
start
andend
. Ifstart
is null the current position is taken.inherited -
deleteLines(
{Position? start, int? countLines}) → void -
inherited
-
findBlockEnd(
Block block, {Position? blockEnd, Position? startPosition}) → bool -
Searches the end of the block starting at the current position.
block
: specifies the block parameters: start, end, body.blockEnd
: The end of the block is stored here. If null currentPosition is taken.startPosition
: defines the start of the search. If null currentPosition is taken. Returns true: the block has been found. -
findBlockStart(
Block block, {Position? startOfBlock, Position? startPosition, int offsetBackward = 0}) → bool -
Searches (backwards) the start of the block starting at a given position.
block
: specifies the block parameters: start, end, body. The start of the block is stored instartOfBlock
. If null currentPosition is taken.startPosition
: defines the start of the search.offsetBackward
: before starting the start position is moved this offset in direction of text start. Returns true: the block has been found. -
goto(
Position position) → void -
Sets the current position to
position
.inherited -
insert(
String text, {Position? position}) → void -
Inserts a string at a given
position
. Ifposition
is null the currentPosition is taken.inherited -
insertLines(
List< String> textLines, {Position? position}) → void -
Inserts a string list at a given
position
. Ifposition
is null the currentPosition is taken.inherited -
lineByIndex(
int ix) → String -
Returns a line given by its index. May be a part of the stored line
if the currentRegion requires that.
inherited
-
nextBlockFromList(
List< Block> blockList, {Position? position, Position? blockStart, Position? blockEnd, Position? endPosition}) → Block? -
Searches the next block from a given
position
.blockList
is a list of alternative block descriptions. The search starts atposition
. If null the currentPosition is used.blockStart
: OUT: if not null, the start of the found block is stored here.blockEnd
: OUT: if not null, the end of the found block is stored here.endPosition
: OUT: the block end is copied here. If null currentPosition is taken. Returns null if search has failed otherwise the block found. Note: the Block contains an optional name or an intrinsic id to distinct them from other. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
search(
Searcher searcher, {bool skipLastMatch = false, Position? hitPosition, Position? startPosition, RelativePosition relativePosition = RelativePosition.onFirst}) → bool -
Searches a pattern from a given position.
searcher
specifies the kind of pattern: regular expression, raw string...startPosition
defines the position to start. If null the currentPosition is taken.hitPosition
: OUT: the position of the hit. If result is false the value is not changed. If null the currentPosition is used.relativePosition
defines the result position relative to the found pattern.skipLastMatch
: if true the current position is moved below the last found match before the search is started. This is only meaningful if there was a previous call of search and therelativePosition
of the previous call was RelativePosition.onFirst. This parameter makes it easy to find the same pattern multiple times. Note: currentPosition is always set, depending onrelativePosition
. Returns true if the pattern is found. -
searchReverse(
Searcher searcher, {Position? startPosition, int offsetBackward = 0, Position? hitPosition, RelativePosition relativePosition = RelativePosition.onFirst}) → bool -
Searches a pattern from a given position in reverse direction.
startPosition
defines the start. If null the currentPosition is taken.offsetBackward
: the start position is moved this count of characters in direction to the text start before searching. This is meaningful if the start position is the region end: Otherwise nothing will be found.searcher
specifies the kind of pattern: regular expression, raw string...hitPosition
: OUT: the position of the hit. If result is false the value is not changed. If null the currentPosition is used.relativePosition
defines the result position relative to the found pattern. Returns true if the pattern is found. -
startColumnByIndex(
int ix) → int -
Returns the start column of a line given by its index depending on the
currentRegion.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
traverseBlock(
List< BlockEntry> entries, int ixStart, int step, int ixStop, Position endPosition) → bool -
Tests whether the
entries
matches to the lines at a given start position. Note: this method handles both directions, controlled byentries
,ixStart
,step
andixStop
.entries
: the description of the block in the needed order.ixStart
: the first index of lines to inspect.step
: the offset to get the next line: +1 or -1ixStop
: the first index of lines that should not be inspectedendPosition
: if the block is found, the end position will be stored here. Ifstep
is 1 the end position is end of the block, ifstep
is -1 the start of block is meant. Returns true, if the entries match the lines at the current position.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited