Skip to content

Commit 37c14bc

Browse files
committed
rewrite fuzzy search, #5509
1 parent b640518 commit 37c14bc

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

app/proc_str.pas

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,13 @@ function SFindFuzzyPositions(const SText, SFind: UnicodeString): TATIntArray;
112112
//
113113
var
114114
STextUpper: UnicodeString;
115-
i, N, N1, N2: integer;
115+
i, N, N2: integer;
116116
begin
117117
Result:= nil;
118118
STextUpper:= UnicodeUpperCase(SText);
119119

120-
{
121120
//if simple match is found, don't calculate complex fuzzy matches
122-
N:= Pos(SFind, SText);
121+
N:= Pos(UnicodeUpperCase(SFind), UnicodeUpperCase(SText));
123122
if N>0 then
124123
begin
125124
SetLength(Result, Length(SFind));
@@ -128,20 +127,18 @@ function SFindFuzzyPositions(const SText, SFind: UnicodeString): TATIntArray;
128127
Result[i]:= Result[i-1]+1;
129128
exit;
130129
end;
131-
}
132130

133131
//calculate complex matches
134132
SetLength(Result, Length(SFind));
135133
N2:= 0;
136134
for i:= 1 to Length(SFind) do
137135
begin
138-
N1:= N2;
136+
N:= N2;
139137
repeat
140-
N:= N2;
141-
N2:= PosEx(UpCase(SFind[i]), STextUpper, N+1);
138+
N2:= PosEx(UpCase(SFind[i]), STextUpper, N2+1);
142139
if N2=0 then Exit(nil);
143140

144-
if N2=N1+1 then Break;
141+
if N2=N+1 then Break;
145142
if IsCharUpperLetter(SText[N2]) then Break;
146143
if (N2>1) and IsCharSep(SText[N2-1]) then Break;
147144
until false;

0 commit comments

Comments
 (0)