diff options
Diffstat (limited to 'caesar.go')
-rw-r--r-- | caesar.go | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -21,16 +21,13 @@ type RuneRange struct { End rune } -// Contains checks whether r is in the rune range. -func (rr RuneRange) Contains(r rune) bool { +// contains checks whether r is in the rune range. +func (rr RuneRange) contains(r rune) bool { return r >= rr.Start && r <= rr.End } -// Shift shifts r by d within the range, modulo the size of the range. -func (rr RuneRange) Shift(r rune, d int) rune { - if !rr.Contains(r) { - return r - } +// shift shifts r by d within the range, modulo the size of the range. +func (rr RuneRange) shift(r rune, d int) rune { return rr.Start + (r - rr.Start + rune(d)%(rr.End-rr.Start)) } @@ -62,8 +59,8 @@ type shiftFunc func(rune) rune func (c Coder) shifter(delta int) shiftFunc { return func(r rune) rune { for _, rr := range c.Ranges { - if rr.Contains(r) { - return rr.Shift(r, delta) + if rr.contains(r) { + return rr.shift(r, delta) } } return r |