@@ -42,12 +42,14 @@ TStringHashListUtf8 = class(TObject)
4242 private
4343 FList: PStringHashItemList;
4444 FCount: Integer;
45+ fNormalize: Boolean;
4546 fCaseSensitive: Boolean;
4647 function BinarySearch (HashValue: Cardinal): Integer;
4748 function CompareString (const Low, Key: String): Boolean;
4849 function CompareValue (const Value1, Value2: Cardinal): Integer;
4950 procedure FindHashBoundaries (HashValue: Cardinal; StartFrom: Integer; out First, Last: Integer);
5051 function GetData (const S: String): Pointer;
52+ procedure SetNormalize (AValue: Boolean);
5153 procedure SetCaseSensitive (const Value : Boolean);
5254 procedure Delete (Index: Integer);
5355 procedure SetData (const S: String; const AValue: Pointer);
@@ -66,6 +68,7 @@ TStringHashListUtf8 = class(TObject)
6668 function Remove (const S: String): Integer;
6769 function Remove (const S: String; Data: Pointer): Integer;
6870 procedure FindBoundaries (StartFrom: Integer; out First, Last: Integer);
71+ property Normalize: Boolean read fNormalize write SetNormalize;
6972 property CaseSensitive: Boolean read fCaseSensitive write SetCaseSensitive;
7073 property Count: Integer read FCount;
7174 property Data[const S: String]: Pointer read GetData write SetData; default;
@@ -75,7 +78,7 @@ TStringHashListUtf8 = class(TObject)
7578implementation
7679
7780uses
78- LazUTF8;
81+ LazUTF8, DCOSUtils ;
7982
8083{ TStringHashListUtf8 }
8184
@@ -97,6 +100,10 @@ function TStringHashListUtf8.Add(const S: String; ItemData: Pointer): Integer;
97100 else begin
98101 Text:= UTF8LowerCase(S);
99102 end ;
103+ if fNormalize then
104+ begin
105+ Text:= NormalizeFileName(Text);
106+ end ;
100107 New(Item);
101108 Val:= HashOf(Text);
102109 Item^.HashValue := Val;
@@ -180,13 +187,20 @@ function TStringHashListUtf8.CompareString(const Low, Key: String): Boolean;
180187begin
181188 P:= Pointer(Low);
182189 Len:= Length(Low);
190+ if not fNormalize then
191+ begin
192+ LKey:= Key;
193+ end
194+ else begin
195+ LKey:= NormalizeFileName(Key);
196+ end ;
183197 if fCaseSensitive then
184198 begin
185- Result:= (Len = Length(Key ));
186- if Result then Result:= (CompareByte(P^, Pointer(Key )^, Len) = 0 );
199+ Result:= (Len = Length(LKey ));
200+ if Result then Result:= (CompareByte(P^, Pointer(LKey )^, Len) = 0 );
187201 end
188202 else begin
189- LKey:= UTF8LowerCase(Key );
203+ LKey:= UTF8LowerCase(LKey );
190204 Result:= (Len = Length(LKey));
191205 if Result then Result:= (CompareByte(P^, Pointer(LKey)^, Len) = 0 );
192206 end ;
@@ -232,6 +246,18 @@ procedure TStringHashListUtf8.SetData(const S: String; const AValue: Pointer);
232246 Add(S,AValue);
233247end ;
234248
249+ procedure TStringHashListUtf8.SetNormalize (AValue: Boolean);
250+ begin
251+ if fNormalize <> AValue then
252+ begin
253+ if Count > 0 then
254+ begin
255+ raise EListError.Create(lrsListMustBeEmpty);
256+ end ;
257+ fNormalize := AValue;
258+ end ;
259+ end ;
260+
235261destructor TStringHashListUtf8.Destroy;
236262begin
237263 Clear;
@@ -249,6 +275,10 @@ function TStringHashListUtf8.Find(const S: String): Integer;
249275 else begin
250276 Text:= UTF8LowerCase(S);
251277 end ;
278+ if fNormalize then
279+ begin
280+ Text:= NormalizeFileName(Text);
281+ end ;
252282 Value := HashOf(Text);
253283 Result:= BinarySearch(Value );
254284 if (Result <> -1 ) and not CompareString(Text, FList[Result]^.Key) then
@@ -275,6 +305,10 @@ function TStringHashListUtf8.Find(const S: String; Data: Pointer): Integer;
275305 else begin
276306 Text:= UTF8LowerCase(S);
277307 end ;
308+ if fNormalize then
309+ begin
310+ Text:= NormalizeFileName(Text);
311+ end ;
278312 Value := HashOf(Text);
279313 Result:= BinarySearch(Value );
280314 if (Result <> -1 ) and
@@ -335,7 +369,8 @@ procedure TStringHashListUtf8.Insert(Index: Integer; Item: PStringHashItem);
335369
336370constructor TStringHashListUtf8.Create(CaseSensitivity: boolean);
337371begin
338- fCaseSensitive:=CaseSensitivity;
372+ fNormalize:= True;
373+ fCaseSensitive:= CaseSensitivity;
339374 inherited Create;
340375end ;
341376
0 commit comments