--- a/Tools__Tag.st Tue Mar 12 16:45:04 2019 +0100
+++ b/Tools__Tag.st Tue Mar 12 16:46:16 2019 +0100
@@ -420,8 +420,13 @@
!Tag methodsFor:'tag searching'!
-lineNumberIn:someText
- |pat lnr atStart atEnd|
+lineNumberIn:someStringCollectionOrFilename
+ "search the tag and return the line nr or 0, if not found.
+ search either in the collection of lines or the file's contents.
+ This is called with the contents for small files,
+ but with the fileName for huge ones"
+
+ |pat lnr atStartOfLine atEndOfLine findFirst|
(lineNumber notNil and:[lineNumber ~~ 0]) ifTrue:[
^ lineNumber
@@ -429,7 +434,7 @@
(pat := self pattern) isNil ifTrue:[
lineNumber := 1.
- ^ lineNumber
+ ^ lineNumber
].
(pat endsWith:';"') ifTrue:[
@@ -445,33 +450,53 @@
"/ ].
(pat startsWith:$^) ifTrue:[
pat := pat copyFrom:2.
- atStart := true.
+ atStartOfLine := true.
].
(pat endsWith:$$) ifTrue:[
pat := pat copyButLast.
- atEnd := true.
+ atEndOfLine := true.
].
- atStart == true ifTrue:[
- atEnd == true ifTrue:[
- lnr := someText findFirst:[:line | line = pat].
+
+ "/ search either in the collection of lines or the file's contents
+ findFirst :=
+ [:comparer |
+ someStringCollectionOrFilename isFilename ifTrue:[
+ [:exit |
+ |lineNr|
+ lineNr := 1.
+ someStringCollectionOrFilename readingLinesDo:[:line |
+ (comparer value:line) ifTrue:[exit value:lineNr].
+ lineNr := lineNr + 1.
+ ]
+ ] valueWithExit
+ ] ifFalse:[
+ someStringCollectionOrFilename findFirst:comparer
+ ].
+ ].
+
+ atStartOfLine == true ifTrue:[
+ atEndOfLine == true ifTrue:[
+ lnr := findFirst value:[:line | line = pat].
] ifFalse:[
- lnr := someText findFirst:[:line | line startsWith:pat].
+ lnr := findFirst value:[:line | line startsWith:pat].
]
] ifFalse:[
- atEnd == true ifTrue:[
- lnr := someText findFirst:[:line | line endsWith:pat].
+ atEndOfLine == true ifTrue:[
+ lnr := findFirst value:[:line | line endsWith:pat].
] ifFalse:[
- lnr := someText findFirst:[:line | line includesString:pat].
+ lnr := findFirst value:[:line | line includesString:pat].
].
].
lnr == 0 ifTrue:[
- lnr := someText findFirst:[:line | line includesString:self label].
+ lnr := findFirst value:[:line | line includesString:self label].
lnr == 0 ifTrue:[
lnr := 1.
].
].
^ lnr
+
+ "Modified: / 12-03-2019 / 15:08:32 / Claus Gittinger"
! !
!Tag methodsFor:'testing'!