utils.go (867B)
1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package sarif 6 7 import ( 8 "strings" 9 10 "golang.org/x/vuln/internal/govulncheck" 11 ) 12 13 func choose(s1, s2 string, cond bool) string { 14 if cond { 15 return s1 16 } 17 return s2 18 } 19 20 func list(elems []string) string { 21 l := len(elems) 22 if l == 0 { 23 return "" 24 } 25 if l == 1 { 26 return elems[0] 27 } 28 29 cList := strings.Join(elems[:l-1], ", ") 30 return cList + choose("", ",", l == 2) + " and " + elems[l-1] 31 } 32 33 // symbol is simplified adaptation of internal/scan/symbol. 34 func symbol(fr *govulncheck.Frame) string { 35 if fr.Function == "" { 36 return "" 37 } 38 sym := strings.Split(fr.Function, "$")[0] 39 if fr.Receiver != "" { 40 sym = fr.Receiver + "." + sym 41 } 42 if fr.Package != "" { 43 sym = fr.Package + "." + sym 44 } 45 return sym 46 }