Move string list utility functions to android package

Test: m checkbuild
Change-Id: I50a7ccf9fd7ed82b688e3eb90489c0bc0af33287
This commit is contained in:
Colin Cross
2017-12-22 15:47:09 -08:00
parent ba5b43ee44
commit b4330e222b
4 changed files with 49 additions and 57 deletions

View File

@@ -54,7 +54,7 @@ func sortedKeys(m map[string][]string) []string {
return s
}
func indexList(s string, list []string) int {
func IndexList(s string, list []string) int {
for i, l := range list {
if l == s {
return i
@@ -64,11 +64,11 @@ func indexList(s string, list []string) int {
return -1
}
func inList(s string, list []string) bool {
return indexList(s, list) != -1
func InList(s string, list []string) bool {
return IndexList(s, list) != -1
}
func prefixInList(s string, list []string) bool {
func PrefixInList(s string, list []string) bool {
for _, prefix := range list {
if strings.HasPrefix(s, prefix) {
return true
@@ -77,6 +77,37 @@ func prefixInList(s string, list []string) bool {
return false
}
func FilterList(list []string, filter []string) (remainder []string, filtered []string) {
for _, l := range list {
if InList(l, filter) {
filtered = append(filtered, l)
} else {
remainder = append(remainder, l)
}
}
return
}
func RemoveListFromList(list []string, filter_out []string) (result []string) {
result = make([]string, 0, len(list))
for _, l := range list {
if !InList(l, filter_out) {
result = append(result, l)
}
}
return
}
func RemoveFromList(s string, list []string) (bool, []string) {
i := IndexList(s, list)
if i != -1 {
return true, append(list[:i], list[i+1:]...)
} else {
return false, list
}
}
// FirstUniqueStrings returns all unique elements of a slice of strings, keeping the first copy of
// each. It modifies the slice contents in place, and returns a subslice of the original slice.
func FirstUniqueStrings(list []string) []string {