diff options
| author | Jeff Carr <[email protected]> | 2025-10-06 21:59:17 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-06 21:59:17 -0500 |
| commit | b4e05f2ad96598afe502a86c281bcf3fdfb4faf2 (patch) | |
| tree | 5351987a2c0b8edff195ece35b4d8767a2847195 /linesScanner.go | |
| parent | 5e3adeadf40b29f63e0e8236e120aeae124ff82a (diff) | |
correctly compute patchId from gitam file
Diffstat (limited to 'linesScanner.go')
| -rw-r--r-- | linesScanner.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/linesScanner.go b/linesScanner.go new file mode 100644 index 0000000..6677b45 --- /dev/null +++ b/linesScanner.go @@ -0,0 +1,80 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package gitpb + +import ( + "fmt" + sync "sync" +) + +// taken from autogenpb. this should be in some generic library or just in GO +// var allTheLines *LinesScanner + +// newLinesScanner initializes a new LinesScanner iterator with a slice of strings. +func NewLinesScanner(things []string) *LinesScanner { + return &LinesScanner{things: things} +} + +// LinesScanner provides an iterator over a slice of strings, allowing for +// sequential access and the ability to un-scan (step back). +type LinesScanner struct { + sync.Mutex + + things []string + index int +} + +// Scan advances the iterator to the next line. It returns false if there are +// no more lines. +func (it *LinesScanner) Scan() bool { + if it.index >= len(it.things) { + return false + } + it.Lock() + it.index++ + it.Unlock() + return true +} + +// UnScan moves the iterator back one line. It returns false if the iterator +// is already at the beginning. +func (it *LinesScanner) UnScan() bool { + if it.index < 1 { + it.index = 0 + return false + } + it.Lock() + it.index-- + it.Unlock() + return true +} + +// NextRaw returns the current line from the scanner without any modification. +func (it *LinesScanner) NextRaw() string { + if it.index-1 == len(it.things) { + fmt.Println("Next() error in LinesScanner", it.index) + } + return it.things[it.index-1] +} + +func (it *LinesScanner) Err() error { + return nil +} + +// alias as some scanners use Text() +func (it *LinesScanner) Text() string { + return it.Next() +} + +// Next returns the current line from the scanner with leading and trailing +// whitespace removed. +func (it *LinesScanner) Next() string { + if it.index-1 == len(it.things) { + fmt.Println("Next() error in LinesScanner", it.index) + } + // out := commentPreprocessor(it.things[it.index-1]) + out := it.things[it.index-1] + return out + // return out +} |
