commit a56327b484f5adf139e9f6c8f09a79959d3a11af
parent a09761d6846790f59b60c66d1efa721fb5573514
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 17 Nov 2022 13:09:34 -0500
cleanup
Diffstat:
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/cmd/art/main.go b/cmd/art/main.go
@@ -133,22 +133,25 @@ func HexFromRgbColor(color color.NRGBA) string {
return fmt.Sprintf("#%X%X%X", color.R, color.G, color.B)
}
+const firstRune = 'a'
+const lastRune = 'z'
+
+func getNextClassName(in []rune) (out []rune) {
+ out = in
+ for i := len(out) - 1; i >= 0; i-- {
+ if out[i] < lastRune {
+ out[i]++
+ return
+ }
+ out[i] = firstRune
+ }
+ return append([]rune{firstRune}, out...)
+}
+
func getClassName(idx int) string {
- const firstRune = 'a'
- const lastRune = 'z'
out := []rune{firstRune}
-outLoop:
for counter := idx; counter > 0; counter-- {
- // If first letter reached "z", increment the next one which is not yet at "z"
- // If we did not find a suitable letter to increment, let's add a new one in the array, and reset all to "a".
- for i := len(out) - 1; i >= 0; i-- {
- if out[i] < lastRune {
- out[i]++
- continue outLoop
- }
- out[i] = firstRune
- }
- out = append([]rune{firstRune}, out...)
+ out = getNextClassName(out)
}
return string(out)
}