summaryrefslogtreecommitdiff
path: root/caesar.go
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-09-16 15:56:31 -0400
committerBen Burwell <ben@benburwell.com>2019-09-16 16:29:16 -0400
commit679a62a9407c09be0cfb4e22455dca5ae694ce01 (patch)
treea99e8d61ada1677aee6f63a78545463308c5badd /caesar.go
parent528352cddbe0290653c56a27a4134637ad0624e5 (diff)
Flesh out
Diffstat (limited to 'caesar.go')
-rw-r--r--caesar.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/caesar.go b/caesar.go
index d62a26e..191c5b8 100644
--- a/caesar.go
+++ b/caesar.go
@@ -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