29 lines
534 B
Go
29 lines
534 B
Go
|
|
package executor
|
||
|
|
|
||
|
|
import "strings"
|
||
|
|
|
||
|
|
func appendIfMissing(items []string, item string) []string {
|
||
|
|
item = strings.TrimSpace(item)
|
||
|
|
if item == "" {
|
||
|
|
return items
|
||
|
|
}
|
||
|
|
for _, existing := range items {
|
||
|
|
if strings.TrimSpace(existing) == item {
|
||
|
|
return items
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return append(items, item)
|
||
|
|
}
|
||
|
|
|
||
|
|
func preview(text string, limit int) string {
|
||
|
|
text = strings.TrimSpace(text)
|
||
|
|
if text == "" || limit <= 0 {
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
runes := []rune(text)
|
||
|
|
if len(runes) <= limit {
|
||
|
|
return string(runes)
|
||
|
|
}
|
||
|
|
return string(runes[:limit]) + "..."
|
||
|
|
}
|