mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 07:56:36 +01:00
* migrate location structs to file package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * replace source.Location refs with file package call Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove hardlink test for file based catalogers Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove hardlink test for all-regular-files testing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate file resolver implementations to separate package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * [wip] migrate resolvers to internal Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate resolvers to syft/internal Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: <>
40 lines
671 B
Go
40 lines
671 B
Go
package secrets
|
|
|
|
import "io"
|
|
|
|
type newlineCounter struct {
|
|
io.RuneReader
|
|
numBytes int64
|
|
newLines []int64
|
|
}
|
|
|
|
func (c *newlineCounter) ReadRune() (r rune, size int, err error) {
|
|
r, size, err = c.RuneReader.ReadRune()
|
|
c.numBytes += int64(size)
|
|
if r == '\n' {
|
|
c.newLines = append(c.newLines, c.numBytes)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (c *newlineCounter) newlinesBefore(pos int64) int {
|
|
var result int
|
|
for _, nlPos := range c.newLines {
|
|
if nlPos <= pos {
|
|
result++
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (c *newlineCounter) newlinePositionBefore(pos int64) int64 {
|
|
var last int64
|
|
for _, nlPos := range c.newLines {
|
|
if nlPos > pos {
|
|
break
|
|
}
|
|
last = nlPos
|
|
}
|
|
return last
|
|
}
|