line returns the line numbered "lineno" in path, or _,false if lineno is out of range.
(path string, lineno int)
| 972 | |
| 973 | // line returns the line numbered "lineno" in path, or _,false if lineno is out of range. |
| 974 | func (reader *sourceReader) line(path string, lineno int) (string, bool) { |
| 975 | lines, ok := reader.files[path] |
| 976 | if !ok { |
| 977 | // Read and cache file contents. |
| 978 | lines = []string{""} // Skip 0th line |
| 979 | f, err := openSourceFile(path, reader.searchPath, reader.trimPath) |
| 980 | if err != nil { |
| 981 | reader.errors[path] = err |
| 982 | } else { |
| 983 | s := bufio.NewScanner(f) |
| 984 | for s.Scan() { |
| 985 | lines = append(lines, s.Text()) |
| 986 | } |
| 987 | f.Close() |
| 988 | if s.Err() != nil { |
| 989 | reader.errors[path] = err |
| 990 | } |
| 991 | } |
| 992 | reader.files[path] = lines |
| 993 | } |
| 994 | if lineno <= 0 || lineno >= len(lines) { |
| 995 | return "", false |
| 996 | } |
| 997 | return lines[lineno], true |
| 998 | } |
| 999 | |
| 1000 | // openSourceFile opens a source file from a name encoded in a profile. File |
| 1001 | // names in a profile after can be relative paths, so search them in each of |
no test coverage detected