Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions internal/strdist/strdist.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func Distance(a, b string, f CostFunc, cut int64) int64 {
}
lst := make([]CostInt, len(b)+1)
bl := 0
for bi, br := range b {
bl++
for _, br := range b {
cost := f(-1, br)
if cost.InsertB == Inhibit || lst[bi] == Inhibit {
lst[bi+1] = Inhibit
if cost.InsertB == Inhibit || lst[bl] == Inhibit {
lst[bl+1] = Inhibit
} else {
lst[bi+1] = lst[bi] + cost.InsertB
lst[bl+1] = lst[bl] + cost.InsertB
}
bl++
}
lst = lst[:bl+1]
// Not required, but caching means preventing the fast path
Expand Down Expand Up @@ -87,8 +87,7 @@ func Distance(a, b string, f CostFunc, cut int64) int64 {
if debug {
debugf("... %v", lst)
}
_ = stop
if cut != 0 && stop {
if cut != 0 && len(b) > 0 && stop {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not strictly related to unicode but it made the test fail when the second string was empty so I fixed it as well.

break
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/strdist/strdist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var distanceTests = []distanceTest{
{f: strdist.GlobCost, r: 1, a: "a**f/hij", b: "abc/def/hik"},
{f: strdist.GlobCost, r: 2, a: "a**fg", b: "abc/def/hik"},
{f: strdist.GlobCost, r: 0, a: "a**f/hij/klm", b: "abc/d**m"},
{f: strdist.GlobCost, r: 1, a: "**a", b: ""},
}

func (s *S) TestDistance(c *C) {
Expand Down
Loading