diff options
author | George Abbott <george@gabbott.dev> | 2023-11-03 21:06:29 +0000 |
---|---|---|
committer | George Abbott <george@gabbott.dev> | 2023-11-03 21:06:29 +0000 |
commit | 0faa29f2c11a6d906f340397eca5c4bc6d0f1dc6 (patch) | |
tree | 1f67a2956dba869c3c35a1af4c533530e45f9b57 /locate.go |
Diffstat (limited to 'locate.go')
-rw-r--r-- | locate.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/locate.go b/locate.go new file mode 100644 index 0000000..fc9b1b6 --- /dev/null +++ b/locate.go @@ -0,0 +1,33 @@ +package badtudexo + +import ( + st "saggytrousers" +) + +/* locate.go + * The function Locate takes a header, and attempts to locate where a given + * column is in this. For instance, Locate(header, "Unique ID") + * might return 1, as the Unique ID field is in second position. + */ + + +// Locates the index where the needle is found; returns -1 if not found. +func Locate(header []string, needle string) int { + return st.Locate(header, needle) +} + +// Returns the index where the needle is found, returns -1 if not found; +// matches exactly. +func LocateExact[T comparable](header []T, needle T) int { + return st.LocateExact(header, needle) +} + +// Locate the value, or ask where it is from the user. +func LocateOrAsk(header []string, needle, prompt string) int { + v := st.Locate(header, needle) + if v >= 0 { + return v + } + + return st.ChooseFromHeaderPrompt(header, prompt) +} |