Conditions | 8 |
Total Lines | 40 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | package tree |
||
17 | func (s ResultTreeProducer) String(results []scan.Result) string { |
||
18 | sort.Slice(results, func(i, j int) bool { |
||
19 | return results[i].Target.Path < results[j].Target.Path |
||
20 | }) |
||
21 | |||
22 | root := gotree.New("/") |
||
23 | |||
24 | // TODO: improve efficiency |
||
25 | for _, r := range results { |
||
26 | currentBranch := root |
||
27 | |||
28 | parts := strings.Split(r.URL.Path, "/") |
||
29 | for _, p := range parts { |
||
30 | if len(p) == 0 { |
||
31 | continue |
||
32 | } |
||
33 | |||
34 | found := false |
||
35 | |||
36 | for _, item := range currentBranch.Items() { |
||
37 | if item.Text() != p { |
||
38 | continue |
||
39 | } |
||
40 | |||
41 | currentBranch = item |
||
42 | found = true |
||
43 | break |
||
44 | } |
||
45 | |||
46 | if found { |
||
47 | continue |
||
48 | } |
||
49 | |||
50 | newTree := gotree.New(p) |
||
51 | currentBranch.AddTree(newTree) |
||
52 | currentBranch = newTree |
||
53 | } |
||
54 | } |
||
55 | |||
56 | return root.Print() |
||
57 | } |
||
58 |