@@ -98,15 +98,26 @@ function SMaskFilenameSlashes(const fn: string): string;
98
98
result:= StringReplace(result, ' \' , ' |' , [rfReplaceAll]);
99
99
end ;
100
100
101
- function SFindFuzzyPositions (SText, SFind: UnicodeString): TATIntArray;
101
+ function SFindFuzzyPositions (const SText, SFind: UnicodeString): TATIntArray;
102
+ //
103
+ function IsCharSep (const ch: WideChar): boolean;
104
+ begin
105
+ Result:= Pos(ch, ' _.,:;/\-+()[]{}=|' )>0 ;
106
+ end ;
107
+ //
108
+ function IsCharUpperLetter (const ch: WideChar): boolean;
109
+ begin
110
+ Result:= (ch>=' A' ) and (ch<=' Z' );
111
+ end ;
112
+ //
102
113
var
103
- i, N: integer;
114
+ STextUpper: UnicodeString;
115
+ i, N, N1, N2: integer;
104
116
begin
105
117
Result:= nil ;
118
+ STextUpper:= UnicodeUpperCase(SText);
106
119
107
- SText:= UnicodeLowerCase(SText);
108
- SFind:= UnicodeLowerCase(SFind);
109
-
120
+ {
110
121
//if simple match is found, don't calculate complex fuzzy matches
111
122
N:= Pos(SFind, SText);
112
123
if N>0 then
@@ -117,15 +128,25 @@ function SFindFuzzyPositions(SText, SFind: UnicodeString): TATIntArray;
117
128
Result[i]:= Result[i-1]+1;
118
129
exit;
119
130
end;
131
+ }
120
132
121
133
// calculate complex matches
122
- N:= 0 ;
123
134
SetLength(Result, Length(SFind));
135
+ N2:= 0 ;
124
136
for i:= 1 to Length(SFind) do
125
137
begin
126
- N:= PosEx(SFind[i], SText, N+1 );
127
- if N=0 then Exit(nil );
128
- Result[i-1 ]:= N;
138
+ N1:= N2;
139
+ repeat
140
+ N:= N2;
141
+ N2:= PosEx(UpCase(SFind[i]), STextUpper, N+1 );
142
+ if N2=0 then Exit(nil );
143
+
144
+ if N2=N1+1 then Break;
145
+ if IsCharUpperLetter(SText[N2]) then Break;
146
+ if (N2>1 ) and IsCharSep(SText[N2-1 ]) then Break;
147
+ until false;
148
+
149
+ Result[i-1 ]:= N2;
129
150
end ;
130
151
end ;
131
152
0 commit comments