stringify transforms the input parameters into a string list. Arrays and slices are flattened into a sequential list of strings.
(v ...interface{})
| 34 | // stringify transforms the input parameters into a string list. Arrays and |
| 35 | // slices are flattened into a sequential list of strings. |
| 36 | func stringify(v ...interface{}) stringList { |
| 37 | out := stringList{} |
| 38 | for _, v := range v { |
| 39 | switch v := v.(type) { |
| 40 | case nil: |
| 41 | case string: |
| 42 | out = append(out, v) |
| 43 | case []string: |
| 44 | out = append(out, v...) |
| 45 | case stringList: |
| 46 | out = append(out, v...) |
| 47 | default: |
| 48 | switch reflect.TypeOf(v).Kind() { |
| 49 | case reflect.Array, reflect.Slice: |
| 50 | v := reflect.ValueOf(v) |
| 51 | for i, c := 0, v.Len(); i < c; i++ { |
| 52 | out = append(out, stringify(v.Index(i).Interface())...) |
| 53 | } |
| 54 | default: |
| 55 | out = append(out, fmt.Sprintf("%v", v)) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | // Filter out any empty strings |
| 60 | count := 0 |
| 61 | for _, s := range out { |
| 62 | if len(s) > 0 { |
| 63 | out[count] = s |
| 64 | count++ |
| 65 | } |
| 66 | } |
| 67 | return out[:count] |
| 68 | } |
| 69 | |
| 70 | // Strings returns the arguments as a string list. |
| 71 | func (Functions) Strings(v ...interface{}) stringList { |