summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJian Zhen <zhenjl@gmail.com>2015-08-29 14:01:52 -0700
committerJian Zhen <zhenjl@gmail.com>2015-08-29 14:01:52 -0700
commit56e4718818e8dc4ea5ba6348402fc7661863732a (patch)
treed2bb25430c04963380222af35cae2c63bf6d23a7
parent50abeb2d774ccedc6016f21828f299ccfe2ee8b1 (diff)
fixed #2
added length check for step1b
-rw-r--r--porter2.go24
-rw-r--r--porter2_test.go8
2 files changed, 20 insertions, 12 deletions
diff --git a/porter2.go b/porter2.go
index 9609887..ef572b8 100644
--- a/porter2.go
+++ b/porter2.go
@@ -493,20 +493,22 @@ switch1b:
}
rs = rs[:l-m]
- r, rr := rs[len(rs)-1], rs[len(rs)-2]
+ if len(rs) > 2 {
+ r, rr := rs[len(rs)-1], rs[len(rs)-2]
- // if the word ends at, bl or iz add e (so luxuriat -> luxuriate)
- if (rr == 'a' && r == 't') || (rr == 'b' && r == 'l') || (rr == 'i' && r == 'z') {
- rs = append(rs, 'e')
- break switch1b
- }
+ // if the word ends at, bl or iz add e (so luxuriat -> luxuriate)
+ if (rr == 'a' && r == 't') || (rr == 'b' && r == 'l') || (rr == 'i' && r == 'z') {
+ rs = append(rs, 'e')
+ break switch1b
+ }
- // if the word ends with a double remove the last letter (so hopp -> hop)
- switch r {
- case 'b', 'd', 'f', 'g', 'm', 'n', 'p', 'r', 't':
+ // if the word ends with a double remove the last letter (so hopp -> hop)
if r == rr {
- rs = rs[:len(rs)-1]
- break switch1b
+ switch r {
+ case 'b', 'd', 'f', 'g', 'm', 'n', 'p', 'r', 't':
+ rs = rs[:len(rs)-1]
+ break switch1b
+ }
}
}
diff --git a/porter2_test.go b/porter2_test.go
index 800a807..d0d8df3 100644
--- a/porter2_test.go
+++ b/porter2_test.go
@@ -23,7 +23,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "github.com/surgebase/glog"
+ "github.com/surge/glog"
)
var (
@@ -84,6 +84,9 @@ var (
[]rune("fizzed"),
[]rune("failing"),
[]rune("filing"),
+ []rune("aed"),
+ []rune("aing"),
+ []rune("eing"),
}
expect1b [][]rune = [][]rune{
@@ -103,6 +106,9 @@ var (
[]rune("fizz"),
[]rune("fail"),
[]rune("file"),
+ []rune("a"),
+ []rune("a"),
+ []rune("e"),
}
data1c [][]rune = [][]rune{