Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3f4d750d
authored
2014-05-20 14:32:06 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
utils: improve the file grep
1 parent
9f01aeed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
utils/file.go
utils/file.go
View file @
3f4d750
...
...
@@ -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
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment