|
...
|
...
|
@@ -145,6 +145,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
|
|
145
|
145
|
|
|
146
|
146
|
/* backtrace to find the positions of optimal matching */
|
|
147
|
147
|
if(positions){
|
|
|
148
|
+ int match_required = 0;
|
|
148
|
149
|
for(int i = n-1, j = m-1; i >= 0; i--){
|
|
149
|
150
|
for(; j >= 0; j--){
|
|
150
|
151
|
/*
|
|
...
|
...
|
@@ -155,7 +156,12 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
|
|
155
|
156
|
* we encounter, the latest in the candidate
|
|
156
|
157
|
* string.
|
|
157
|
158
|
*/
|
|
158
|
|
- if(D[i][j] != SCORE_MIN && D[i][j] == M[i][j]){
|
|
|
159
|
+ if(D[i][j] != SCORE_MIN && (match_required || D[i][j] == M[i][j])){
|
|
|
160
|
+ /* If this score was determined using
|
|
|
161
|
+ * SCORE_MATCH_CONSECUTIVE, the
|
|
|
162
|
+ * previous character MUST be a match
|
|
|
163
|
+ */
|
|
|
164
|
+ match_required = i && j && M[i][j] == D[i-1][j-1] + SCORE_MATCH_CONSECUTIVE;
|
|
159
|
165
|
positions[i] = j--;
|
|
160
|
166
|
break;
|
|
161
|
167
|
}
|