package saggytrousers import ( "strings" ) // For Locate, LocateExact func preprocess(s string) string { s = strings.ToLower(s) s = strings.ReplaceAll(s, " ", "") s = strings.ReplaceAll(s, "-", "") return s } // This function is needed for SelectHeader. So we put it in saggytrousers, and // the badtudexo.Locate function calls this. // For all other types, including []any, please call LocateExact. func Locate(header []string, needle string) int { // Perform preprocessing of header and needle var cneedle string var cheader []string cneedle = preprocess(needle) for _, v := range header { cheader = append(cheader, preprocess(v)) } return LocateExact(cheader, cneedle) } // Returns the index where the needle is found, returns -1 if not found; // matches exactly. func LocateExact[T comparable](header []T, needle T) int { for i := 0; i < len(header); i++ { if header[i] == needle { return i } } return -1 }