runeint.go 458 B

12345678910111213141516171819
  1. package utils
  2. // RuneToInt converts a rune between '0' and '9' to an integer between 0 and 9
  3. // If the rune is outside of this range -1 is returned.
  4. func RuneToInt(r rune) int {
  5. if r >= '0' && r <= '9' {
  6. return int(r - '0')
  7. }
  8. return -1
  9. }
  10. // IntToRune converts a digit 0 - 9 to the rune '0' - '9'. If the given int is outside
  11. // of this range 'F' is returned!
  12. func IntToRune(i int) rune {
  13. if i >= 0 && i <= 9 {
  14. return rune(i + '0')
  15. }
  16. return 'F'
  17. }