summaryrefslogtreecommitdiff
path: root/android/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/util.go')
-rw-r--r--android/util.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/android/util.go b/android/util.go
index 3c0af2f38..2d269b724 100644
--- a/android/util.go
+++ b/android/util.go
@@ -177,6 +177,41 @@ func setFromList[T comparable](l []T) map[T]bool {
return m
}
+// PrettyConcat returns the formatted concatenated string suitable for displaying user-facing
+// messages.
+func PrettyConcat(list []string, quote bool, lastSep string) string {
+ if len(list) == 0 {
+ return ""
+ }
+
+ quoteStr := func(v string) string {
+ if !quote {
+ return v
+ }
+ return fmt.Sprintf("%q", v)
+ }
+
+ if len(list) == 1 {
+ return quoteStr(list[0])
+ }
+
+ var sb strings.Builder
+ for i, val := range list {
+ if i > 0 {
+ sb.WriteString(", ")
+ }
+ if i == len(list)-1 {
+ sb.WriteString(lastSep)
+ if lastSep != "" {
+ sb.WriteString(" ")
+ }
+ }
+ sb.WriteString(quoteStr(val))
+ }
+
+ return sb.String()
+}
+
// ListSetDifference checks if the two lists contain the same elements. It returns
// a boolean which is true if there is a difference, and then returns lists of elements
// that are in l1 but not l2, and l2 but not l1.