summaryrefslogtreecommitdiff
path: root/src/cmd/godoc/index.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/godoc/index.go')
-rw-r--r--src/cmd/godoc/index.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go
index 3d2c3ff96..6c36e6f4f 100644
--- a/src/cmd/godoc/index.go
+++ b/src/cmd/godoc/index.go
@@ -44,7 +44,6 @@ import (
"errors"
"go/ast"
"go/parser"
- "go/scanner"
"go/token"
"index/suffixarray"
"io"
@@ -54,6 +53,7 @@ import (
"sort"
"strings"
"time"
+ "unicode"
)
// ----------------------------------------------------------------------------
@@ -867,7 +867,10 @@ func (x *Index) Write(w io.Writer) error {
return err
}
if fulltext {
- if err := x.fset.Write(w); err != nil {
+ encode := func(x interface{}) error {
+ return gob.NewEncoder(w).Encode(x)
+ }
+ if err := x.fset.Write(encode); err != nil {
return err
}
if err := x.suffixes.Write(w); err != nil {
@@ -893,7 +896,10 @@ func (x *Index) Read(r io.Reader) error {
x.snippets = fx.Snippets
if fx.Fulltext {
x.fset = token.NewFileSet()
- if err := x.fset.Read(r); err != nil {
+ decode := func(x interface{}) error {
+ return gob.NewDecoder(r).Decode(x)
+ }
+ if err := x.fset.Read(decode); err != nil {
return err
}
x.suffixes = new(suffixarray.Index)
@@ -921,15 +927,15 @@ func (x *Index) lookupWord(w string) (match *LookupResult, alt *AltWords) {
return
}
+// isIdentifier reports whether s is a Go identifier.
func isIdentifier(s string) bool {
- var S scanner.Scanner
- fset := token.NewFileSet()
- S.Init(fset.AddFile("", fset.Base(), len(s)), []byte(s), nil, 0)
- if _, tok, _ := S.Scan(); tok == token.IDENT {
- _, tok, _ := S.Scan()
- return tok == token.EOF
+ for i, ch := range s {
+ if unicode.IsLetter(ch) || ch == ' ' || i > 0 && unicode.IsDigit(ch) {
+ continue
+ }
+ return false
}
- return false
+ return len(s) > 0
}
// For a given query, which is either a single identifier or a qualified