-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As decoder now can know they are decoding as part of probing we can now use some heuristics to see if we should decode as html. The reason heuristics is needed is that x/html parser will alwaus succeed. Add lazyre package to help delay compile of RE and make it concurrency safe.
- Loading branch information
Showing
16 changed files
with
1,058 additions
and
975 deletions.
There are no files selected for viewing
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ $ fq -n _registry.groups.probe | |
"mpeg_ts", | ||
"wav", | ||
"json", | ||
"html", | ||
"jsonl", | ||
"toml", | ||
"xml", | ||
|
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<!DOCTYPE bla SYSTEM "" []> | ||
<head> | ||
<title>aaa</title> | ||
</head> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/html.html: | ||
|
||
<html><a> | ||
|
||
$ fq . html.html | ||
{ | ||
"html": { | ||
"body": { | ||
"a": "" | ||
}, | ||
"head": "" | ||
} | ||
} | ||
/doctype.html: | ||
|
||
<!DOCTYPE html> | ||
<a> | ||
|
||
$ fq . doctype.html | ||
{ | ||
"html": { | ||
"body": { | ||
"a": "" | ||
}, | ||
"head": "" | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// lazyre lazily compiles a *regexp.Regexp in concurrency safe way | ||
// Use &lazyre.RE{S: `...`} or call New | ||
package lazyre | ||
|
||
import ( | ||
"regexp" | ||
"sync" | ||
) | ||
|
||
type RE struct { | ||
S string | ||
|
||
m sync.RWMutex | ||
re *regexp.Regexp | ||
} | ||
|
||
// New creates a new *lazyRE | ||
func New(s string) *RE { | ||
return &RE{S: s} | ||
} | ||
|
||
// Must compiles regexp, returned *regexp.Regexp can be stored away and reused | ||
func (lr *RE) Must() *regexp.Regexp { | ||
lr.m.Lock() | ||
defer lr.m.Unlock() | ||
if lr.re == nil { | ||
lr.re = regexp.MustCompile(lr.S) | ||
} | ||
return lr.re | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lazyre_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/wader/fq/internal/lazyre" | ||
) | ||
|
||
func TestMust(t *testing.T) { | ||
if !lazyre.New("a").Must().MatchString("a") { | ||
t.Fatal("should compile and be non-nil and match a") | ||
} | ||
} |
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