diff options
author | Rob Pike <r@golang.org> | 2009-04-21 22:46:19 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-04-21 22:46:19 -0700 |
commit | d408d11a1cc190f9f6278c2d98e82f4e200d92df (patch) | |
tree | 8f2c2e191d17c2846db871d340872c9fa4dfda99 | |
parent | f9f877f216b964e0ee1b765be4b63aaa3d4f10fe (diff) | |
download | golang-d408d11a1cc190f9f6278c2d98e82f4e200d92df.tar.gz |
allow godoc to match on regular expressions.
if the name contains a metacharacter, use regexp matching;
otherwise require strict equality.
now
godoc flag '.*Var'
can give you all the FooVar functions.
R=gri
DELTA=19 (19 added, 0 deleted, 0 changed)
OCL=27711
CL=27713
-rw-r--r-- | usr/gri/pretty/docprinter.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/usr/gri/pretty/docprinter.go b/usr/gri/pretty/docprinter.go index 87b973e27..88651b288 100644 --- a/usr/gri/pretty/docprinter.go +++ b/usr/gri/pretty/docprinter.go @@ -453,8 +453,26 @@ func (doc *DocReader) Doc() *PackageDoc { // ---------------------------------------------------------------------------- // Filtering by name +// Does s look like a regular expression? +func isRegexp(s string) bool { + metachars := ".(|)*+?^$[]"; + for i, c := range s { + for j, m := range metachars { + if c == m { + return true + } + } + } + return false +} + func match(s string, a []string) bool { for i, t := range a { + if isRegexp(t) { + if matched, err := regexp.Match(t, s); matched { + return true; + } + } if s == t { return true; } @@ -516,6 +534,7 @@ func filterFuncDocs(a []*FuncDoc, names []string) []*FuncDoc { // Filter eliminates information from d that is not // about one of the given names. // TODO: Recognize "Type.Method" as a name. +// TODO(r): maybe precompile the regexps. func (p *PackageDoc) Filter(names []string) { p.Consts = filterValueDocs(p.Consts, names); p.Vars = filterValueDocs(p.Vars, names); |