Skip to content

Commit 76657cd

Browse files
committed
Reduce code complexity
Signed-off-by: Peter Verraedt <peter@verraedt.be>
1 parent 10a010d commit 76657cd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

cmd/iron/tabwriter/tabwriter.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ func (tw *TabWriter) outputRows(rows [][]string, widths []int) error {
6161

6262
for j, cell := range row {
6363
if slices.Contains(tw.HideColumns, j) {
64-
output.WriteString(abbreviate(cell, 0))
65-
66-
if len(cell) > 0 && (cell[len(cell)-1] == '\n' || cell[len(cell)-1] == '\f') {
67-
output.WriteByte(cell[len(cell)-1])
68-
}
64+
output.WriteString(emptyCell(cell))
6965

7066
continue
7167
}
@@ -91,6 +87,20 @@ func (tw *TabWriter) outputRows(rows [][]string, widths []int) error {
9187
return err
9288
}
9389

90+
func emptyCell(cell string) string {
91+
if cell == "" {
92+
return ""
93+
}
94+
95+
abbr := abbreviate(cell, 0)
96+
97+
if cell[len(cell)-1] == '\n' || cell[len(cell)-1] == '\f' {
98+
abbr += cell[len(cell)-1:]
99+
}
100+
101+
return abbr
102+
}
103+
94104
func findCell(buf []byte) (string, int, []byte) {
95105
var (
96106
cell string

0 commit comments

Comments
 (0)