normalizeExpands normalizes expand strings and merges self containing paths (eg. ["a.b.c", "a.b", " test ", " ", "test"] -> ["a.b.c", "test"]).
(paths []string)
| 258 | // normalizeExpands normalizes expand strings and merges self containing paths |
| 259 | // (eg. ["a.b.c", "a.b", " test ", " ", "test"] -> ["a.b.c", "test"]). |
| 260 | func normalizeExpands(paths []string) []string { |
| 261 | // normalize paths |
| 262 | normalized := make([]string, 0, len(paths)) |
| 263 | for _, p := range paths { |
| 264 | p = strings.ReplaceAll(p, " ", "") // replace spaces |
| 265 | p = strings.Trim(p, ".") // trim incomplete paths |
| 266 | if p != "" { |
| 267 | normalized = append(normalized, p) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // merge containing paths |
| 272 | result := make([]string, 0, len(normalized)) |
| 273 | for i, p1 := range normalized { |
| 274 | var skip bool |
| 275 | for j, p2 := range normalized { |
| 276 | if i == j { |
| 277 | continue |
| 278 | } |
| 279 | if strings.HasPrefix(p2, p1+".") { |
| 280 | // skip because there is more detailed expand path |
| 281 | skip = true |
| 282 | break |
| 283 | } |
| 284 | } |
| 285 | if !skip { |
| 286 | result = append(result, p1) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return list.ToUniqueStringSlice(result) |
| 291 | } |
no test coverage detected
searching dependent graphs…