osnovno iskanje

This commit is contained in:
2026-01-15 12:44:21 +01:00
commit 1ffb58452a
3 changed files with 35 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*grep2electricbogaloo*

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.govekar.net/grep2electricbogaloo
go 1.25.5

31
main.go Normal file
View File

@@ -0,0 +1,31 @@
package main
import (
"bufio"
"os"
)
func matchEngine(pattern string, line string) {
// sliding window approach for simple full pattern matching
for i := 0; i < len(line)-len(pattern); i++ {
slice := line[i : i+len(pattern)]
if slice == pattern {
println(line)
}
}
}
func processReader(src string, r *os.File, pattern string) {
scanner := bufio.NewScanner(r)
line := 0
for scanner.Scan() {
line++
text := scanner.Text()
matchEngine(pattern, text)
}
}
func main() {
pattern := os.Args[1]
processReader("stdin", os.Stdin, pattern)
}