2019-11-29 13:32:07 +00:00
|
|
|
package common
|
2019-11-27 19:24:12 +00:00
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// Appends the appendee to the array if it does not contain appendee yet
|
2019-11-29 13:32:07 +00:00
|
|
|
func AppendIfUnique(appendee string, array []string) []string {
|
2019-11-27 19:24:12 +00:00
|
|
|
// Iterate over all elements and check values
|
|
|
|
for _, elem := range array {
|
|
|
|
if elem == appendee {
|
|
|
|
// ... found. Stop here
|
|
|
|
return array
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// None found, append
|
|
|
|
return append(array, appendee)
|
|
|
|
}
|
|
|
|
|
2019-12-03 22:51:03 +00:00
|
|
|
// Generates a small ASCII tree for the given string array
|
|
|
|
func GenerateTree(strarr []string) string {
|
|
|
|
tmpstr := ""
|
|
|
|
|
2019-11-27 19:24:12 +00:00
|
|
|
// iterate over each element
|
|
|
|
for iter, elem := range strarr {
|
|
|
|
// check if we got the last element
|
|
|
|
if iter < len(strarr) - 1 {
|
2019-12-09 11:15:36 +00:00
|
|
|
tmpstr = fmt.Sprintf("%s├ %s\n", tmpstr, elem)
|
2019-11-27 19:24:12 +00:00
|
|
|
} else {
|
2019-12-09 11:15:36 +00:00
|
|
|
tmpstr = fmt.Sprintf( "%s╰ %s\n", tmpstr, elem)
|
2019-11-27 19:24:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-03 22:51:03 +00:00
|
|
|
|
|
|
|
// Return constructed (grown?) tree
|
|
|
|
return tmpstr
|
2019-11-27 19:24:12 +00:00
|
|
|
}
|