Skip to content

Commit

Permalink
examples/7GUIs/cells: generate printable column labels for large colu…
Browse files Browse the repository at this point in the history
…mn indices

For #126
  • Loading branch information
pwiecz committed May 4, 2024
1 parent 1cdd9eb commit 9e661cf
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion examples/7GUIs/cells/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,25 @@ func (row CellRow) String() string {

type CellCol int

func reverse(s []byte) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}

func (col CellCol) String() string {
return string('A' + byte(col))
// 'A', ... 'Z', 'AA', 'AB', ... 'AZ', 'BA', ... 'BZ', ... 'ZZ', 'AAA', ...
var stringBytes []byte
for true {

Check failure on line 148 in examples/7GUIs/cells/context.go

View workflow job for this annotation

GitHub Actions / build

should use for {} instead of for true {} (S1006)
stringBytes = append(stringBytes, 'A'+byte(col%26))
col /= 26
if col <= 0 {
break
}
col -= 1
}
reverse(stringBytes)
return string(stringBytes)
}

type CellLoc struct {
Expand Down

0 comments on commit 9e661cf

Please sign in to comment.