transformListOrMapping transforms pairs of strings that may be represented as a map, or a list of '=' or ':' separated strings, into a list of ':' separated strings.
(listOrMapping any, sep string, allowNil bool, allowSeps []string)
| 820 | // a map, or a list of '=' or ':' separated strings, into a list of ':' separated |
| 821 | // strings. |
| 822 | func transformListOrMapping(listOrMapping any, sep string, allowNil bool, allowSeps []string) []string { |
| 823 | switch value := listOrMapping.(type) { |
| 824 | case map[string]any: |
| 825 | return toStringList(value, sep, allowNil) |
| 826 | case []any: |
| 827 | result := make([]string, 0, len(value)) |
| 828 | for _, entry := range value { |
| 829 | for i, allowSep := range allowSeps { |
| 830 | entry := fmt.Sprint(entry) |
| 831 | k, v, ok := strings.Cut(entry, allowSep) |
| 832 | if ok { |
| 833 | // Entry uses this allowed separator. Add it to the result, using |
| 834 | // sep as a separator. |
| 835 | result = append(result, fmt.Sprintf("%s%s%s", k, sep, v)) |
| 836 | break |
| 837 | } else if i == len(allowSeps)-1 { |
| 838 | // No more separators to try, keep the entry if allowNil. |
| 839 | if allowNil { |
| 840 | result = append(result, k) |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | return result |
| 846 | } |
| 847 | panic(fmt.Errorf("expected a map or a list, got %T: %#v", listOrMapping, listOrMapping)) |
| 848 | } |
| 849 | |
| 850 | func transformMappingOrListFunc(sep string, allowNil bool) TransformerFunc { |
| 851 | return func(data any) (any, error) { |
no test coverage detected
searching dependent graphs…