mirror of
https://github.com/astaxie/beego.git
synced 2024-12-26 12:00:50 +00:00
utils: improve the file grep
This commit is contained in:
parent
9f01aeed31
commit
3f4d750dc4
@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
|
||||
lines = make([]string, 0)
|
||||
reader := bufio.NewReader(fd)
|
||||
prefix := ""
|
||||
isLongLine := false
|
||||
for {
|
||||
byteLine, isPrefix, er := reader.ReadLine()
|
||||
if er != nil && er != io.EOF {
|
||||
return nil, er
|
||||
}
|
||||
if er == io.EOF {
|
||||
break
|
||||
}
|
||||
line := string(byteLine)
|
||||
if isPrefix {
|
||||
prefix += line
|
||||
continue
|
||||
} else {
|
||||
isLongLine = true
|
||||
}
|
||||
|
||||
line = prefix + line
|
||||
if isLongLine {
|
||||
prefix = ""
|
||||
}
|
||||
if re.MatchString(line) {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
if er == io.EOF {
|
||||
break
|
||||
}
|
||||
}
|
||||
return lines, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user