// 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 }