git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/utils/runeint.go (about) 1 package utils 2 3 // RuneToInt converts a rune between '0' and '9' to an integer between 0 and 9 4 // If the rune is outside of this range -1 is returned. 5 func RuneToInt(r rune) int { 6 if r >= '0' && r <= '9' { 7 return int(r - '0') 8 } 9 return -1 10 } 11 12 // IntToRune converts a digit 0 - 9 to the rune '0' - '9'. If the given int is outside 13 // of this range 'F' is returned! 14 func IntToRune(i int) rune { 15 if i >= 0 && i <= 9 { 16 return rune(i + '0') 17 } 18 return 'F' 19 }