fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

1// Copyright 2016 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package ctags 16 17import ( 18 "fmt" 19 "strconv" 20 "strings" 21) 22 23// Parse parses a single line of exuberant "ctags -n" output. 24func Parse(in string) (*Entry, error) { 25 fields := strings.Split(in, "\t") 26 e := Entry{} 27 28 if len(fields) < 3 { 29 return nil, fmt.Errorf("too few fields: %q", in) 30 } 31 32 e.Name = fields[0] 33 e.Path = fields[1] 34 35 lstr := fields[2] 36 if len(lstr) < 2 { 37 return nil, fmt.Errorf("got %q for linenum field", lstr) 38 } 39 40 l, err := strconv.ParseInt(lstr[:len(lstr)-2], 10, 64) 41 if err != nil { 42 return nil, err 43 } 44 e.Line = int(l) 45 e.Kind = fields[3] 46 47field: 48 for _, f := range fields[3:] { 49 if string(f) == "file:" { 50 e.FileLimited = true 51 } 52 for _, p := range []string{"class", "enum"} { 53 if strings.HasPrefix(f, p+":") { 54 e.Parent = strings.TrimPrefix(f, p+":") 55 e.ParentKind = p 56 continue field 57 } 58 } 59 } 60 return &e, nil 61}