diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-08-30 19:35:33 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-08-30 19:48:29 -0700 |
commit | 57e9b44d776259838fe44609bb717cef8caef4e1 (patch) | |
tree | 5c1e4a8962c50b6a3d78c8df79a9b3f189f39d06 | |
parent | 02b6232f7fdc780868481b101ddea1cd7968bb56 (diff) |
Fix backtrace regarding SCORE_MATCH_CONSECUTIVE
-rw-r--r-- | match.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -145,6 +145,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio /* backtrace to find the positions of optimal matching */ if(positions){ + int match_required = 0; for(int i = n-1, j = m-1; i >= 0; i--){ for(; j >= 0; j--){ /* @@ -155,7 +156,12 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio * we encounter, the latest in the candidate * string. */ - if(D[i][j] != SCORE_MIN && D[i][j] == M[i][j]){ + if(D[i][j] != SCORE_MIN && (match_required || D[i][j] == M[i][j])){ + /* If this score was determined using + * SCORE_MATCH_CONSECUTIVE, the + * previous character MUST be a match + */ + match_required = i && j && M[i][j] == D[i-1][j-1] + SCORE_MATCH_CONSECUTIVE; positions[i] = j--; break; } |