Skip to content

Commit dff1afc

Browse files
committed
Rename escapeForDot => escapeAllForDot; escapeStringForDot => escapeForDot
1 parent 72389be commit dff1afc

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

internal/graph/dotgraph.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (b *builder) addLegend() {
127127
}
128128
title := labels[0]
129129
fmt.Fprintf(b, `subgraph cluster_L { "%s" [shape=box fontsize=16`, title)
130-
fmt.Fprintf(b, ` label="%s\l"`, strings.Join(escapeForDot(labels), `\l`))
130+
fmt.Fprintf(b, ` label="%s\l"`, strings.Join(escapeAllForDot(labels), `\l`))
131131
if b.config.LegendURL != "" {
132132
fmt.Fprintf(b, ` URL="%s" target="_blank"`, b.config.LegendURL)
133133
}
@@ -187,7 +187,7 @@ func (b *builder) addNode(node *Node, nodeID int, maxFlat float64) {
187187

188188
// Create DOT attribute for node.
189189
attr := fmt.Sprintf(`label="%s" id="node%d" fontsize=%d shape=%s tooltip="%s (%s)" color="%s" fillcolor="%s"`,
190-
label, nodeID, fontSize, shape, escapeStringForDot(node.Info.PrintableName()), cumValue,
190+
label, nodeID, fontSize, shape, escapeForDot(node.Info.PrintableName()), cumValue,
191191
dotColor(float64(node.CumValue())/float64(abs64(b.config.Total)), false),
192192
dotColor(float64(node.CumValue())/float64(abs64(b.config.Total)), true))
193193

@@ -305,8 +305,8 @@ func (b *builder) addEdge(edge *Edge, from, to int, hasNodelets bool) {
305305
arrow = "..."
306306
}
307307
tooltip := fmt.Sprintf(`"%s %s %s (%s)"`,
308-
escapeStringForDot(edge.Src.Info.PrintableName()), arrow,
309-
escapeStringForDot(edge.Dest.Info.PrintableName()), w)
308+
escapeForDot(edge.Src.Info.PrintableName()), arrow,
309+
escapeForDot(edge.Dest.Info.PrintableName()), w)
310310
attr = fmt.Sprintf(`%s tooltip=%s labeltooltip=%s`, attr, tooltip, tooltip)
311311

312312
if edge.Residual {
@@ -383,7 +383,7 @@ func dotColor(score float64, isBackground bool) string {
383383

384384
func multilinePrintableName(info *NodeInfo) string {
385385
infoCopy := *info
386-
infoCopy.Name = escapeStringForDot(ShortenFunctionName(infoCopy.Name))
386+
infoCopy.Name = escapeForDot(ShortenFunctionName(infoCopy.Name))
387387
infoCopy.Name = strings.Replace(infoCopy.Name, "::", `\n`, -1)
388388
infoCopy.Name = strings.Replace(infoCopy.Name, ".", `\n`, -1)
389389
if infoCopy.File != "" {
@@ -474,16 +474,18 @@ func min64(a, b int64) int64 {
474474
return b
475475
}
476476

477-
// escapeForDot escapes double quotes and backslashes, and replaces Graphviz's
478-
// "center" character (\n) with a left-justified character.
479-
// See https://graphviz.org/doc/info/attrs.html#k:escString for more info.
480-
func escapeForDot(in []string) []string {
477+
// Applies escapeForDot to all strings in the given slice.
478+
func escapeAllForDot(in []string) []string {
481479
var out = make([]string, len(in))
482480
for i := range in {
483-
out[i] = escapeStringForDot(in[i])
481+
out[i] = escapeForDot(in[i])
484482
}
485483
return out
486484
}
487-
func escapeStringForDot(str string) string {
485+
486+
// escapeForDot escapes double quotes and backslashes, and replaces Graphviz's
487+
// "center" character (\n) with a left-justified character.
488+
// See https://graphviz.org/doc/info/attrs.html#k:escString for more info.
489+
func escapeForDot(str string) string {
488490
return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(str, `\`, `\\`), `"`, `\"`), "\n", `\l`)
489491
}

internal/graph/dotgraph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ func TestEscapeForDot(t *testing.T) {
375375
},
376376
} {
377377
t.Run(tc.desc, func(t *testing.T) {
378-
if got := escapeForDot(tc.input); !reflect.DeepEqual(got, tc.want) {
379-
t.Errorf("escapeForDot(%s) = %s, want %s", tc.input, got, tc.want)
378+
if got := escapeAllForDot(tc.input); !reflect.DeepEqual(got, tc.want) {
379+
t.Errorf("escapeAllForDot(%s) = %s, want %s", tc.input, got, tc.want)
380380
}
381381
})
382382
}

0 commit comments

Comments
 (0)