Skip to content

Commit

Permalink
switch order of conversion to string
Browse files Browse the repository at this point in the history
  • Loading branch information
adelelopez committed May 20, 2015
1 parent 547f555 commit 51caf68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions metaphone.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ type phoneticData struct {
}

func (p *phoneticData) beginsWith(matches ...string) bool {
start := strings.LastIndex(string(p.word[:p.cur]), " ")
start := strings.LastIndex(string(p.word)[:p.cur], " ")
if start != -1 {
for _, str := range matches {

if strings.Contains(string(p.word[start:p.cur]), " "+str) {
if strings.Contains(string(p.word)[start:p.cur], " "+str) {
return true
}
}
Expand All @@ -75,11 +75,11 @@ func (p *phoneticData) beginsWith(matches ...string) bool {
}

func (p *phoneticData) endsWith(matches ...string) bool {
end := strings.Index(string(p.word[p.cur:]), " ")
end := strings.Index(string(p.word)[p.cur:], " ")
if end != -1 {
for _, str := range matches {

if strings.Contains(string(p.word[p.cur:p.cur+end+1]), str+" ") {
if strings.Contains(string(p.word)[p.cur:p.cur+end+1], str+" ") {
return true
}
}
Expand Down Expand Up @@ -115,6 +115,7 @@ func (p *phoneticData) matchesAny(pos int, matches ...string) bool {
}
}
}

return false
}

Expand Down Expand Up @@ -633,7 +634,7 @@ func Metaphone(s string) (string, string) {

for i, next := range p.word {
if p.cur == i {
// fmt.Println(p.cur, ": ", string(next))
//fmt.Println(p.cur, ": ", string(next))
switch next {
case 'a', 'e', 'i', 'o', 'u', 'y':
if p.matchesAny(-1, " ") {
Expand Down
1 change: 1 addition & 0 deletions metaphone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Test(t *testing.T) {
printMetaphonePair("Chianti")
printMetaphonePair("Christopher")
printMetaphonePair("Czerny")
printMetaphonePair("Ççedallemas") // should give (sstlms, sstms)
printMetaphonePair("Danger")
printMetaphonePair("drought")
printMetaphonePair("Edgar")
Expand Down

0 comments on commit 51caf68

Please sign in to comment.