util: Handle negative values for NumToAlpha

This shouldn't be used often, but it makes writing some kinds of code
easier.
This commit is contained in:
James Shubin
2023-06-29 15:14:06 -04:00
parent 97c7d176f0
commit df9b338279
2 changed files with 4 additions and 0 deletions

View File

@@ -33,6 +33,9 @@ import (
// you specify 0, you'll get `a`, 25 gives you `z`, and 26 gives you `aa` and so
// on...
func NumToAlpha(idx int) string {
if idx < 0 {
return "" // don't error or produce junk
}
var mod = idx % 26
var div = idx / 26
if div > 0 {