Created
May 15, 2014 00:07
-
-
Save frohoff/52cb94c95e79640d746f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"bufio" | |
"regexp" | |
"io" | |
) | |
func main() { | |
restr := os.Args[1] | |
re, _ := regexp.Compile(restr) | |
fmt.Println(re) | |
n := 4 | |
iobuf := make([]byte, n) | |
buf := make([]byte, n*2) | |
in := bufio.NewReader(os.Stdin) | |
chunk := -1 | |
lastFound := make(map[int]string) | |
curFound := make(map[int]string) | |
for { | |
b, e := in.Read(iobuf) | |
if e != nil && e != io.EOF { panic(e) } | |
if b == 0 { break } | |
copy(buf[0:n],buf[n:n*2]) | |
copy(buf[n:n*2],iobuf) | |
if chunk == -1 { | |
chunk++ | |
continue | |
} | |
fmt.Println(buf) | |
matches := re.FindAllIndex(buf[0:n+b],-1) | |
for _,m := range matches { | |
fmt.Println(m) | |
rel := m[0]+chunk*n | |
_,ok := lastFound[rel] | |
if ! ok { | |
str := string(buf[m[0]:m[1]]) | |
curFound[rel] = str | |
fmt.Println(rel,`:`,str) | |
} | |
} | |
chunk += 1 | |
lastFound = curFound | |
curFound = make(map[int]string) // reset map | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment