2015-04-08 19:28:14 -04:00
|
|
|
package donut
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func appendUniq(slice []string, i string) []string {
|
|
|
|
for _, ele := range slice {
|
|
|
|
if ele == i {
|
|
|
|
return slice
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return append(slice, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func filterPrefix(objects []string, prefix string) []string {
|
|
|
|
var results []string
|
|
|
|
for _, object := range objects {
|
|
|
|
if strings.HasPrefix(object, prefix) {
|
|
|
|
results = append(results, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
func removePrefix(objects []string, prefix string) []string {
|
|
|
|
var results []string
|
|
|
|
for _, object := range objects {
|
|
|
|
results = append(results, strings.TrimPrefix(object, prefix))
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
func filterDelimited(objects []string, delim string) []string {
|
|
|
|
var results []string
|
|
|
|
for _, object := range objects {
|
|
|
|
if !strings.Contains(object, delim) {
|
|
|
|
results = append(results, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
func filterNotDelimited(objects []string, delim string) []string {
|
|
|
|
var results []string
|
|
|
|
for _, object := range objects {
|
|
|
|
if strings.Contains(object, delim) {
|
|
|
|
results = append(results, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
2015-06-25 18:03:34 -04:00
|
|
|
func extractDelimited(objects []string, delim string) []string {
|
2015-04-08 19:28:14 -04:00
|
|
|
var results []string
|
|
|
|
for _, object := range objects {
|
|
|
|
parts := strings.Split(object, delim)
|
|
|
|
results = append(results, parts[0]+delim)
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
func uniqueObjects(objects []string) []string {
|
|
|
|
objectMap := make(map[string]string)
|
|
|
|
for _, v := range objects {
|
|
|
|
objectMap[v] = v
|
|
|
|
}
|
|
|
|
var results []string
|
|
|
|
for k := range objectMap {
|
|
|
|
results = append(results, k)
|
|
|
|
}
|
|
|
|
sort.Strings(results)
|
|
|
|
return results
|
|
|
|
}
|