mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 09:20:23 +02:00
LazUtils: Add function UTF8CompareTextP, use it in CompareFilenamesP.
git-svn-id: trunk@64391 -
This commit is contained in:
parent
5d09547a8f
commit
4c27531f6f
@ -319,16 +319,12 @@ end;
|
||||
|
||||
function CompareFilenamesP(Filename1, Filename2: PChar;
|
||||
IgnoreCase: boolean = false): integer;
|
||||
{$IFDEF darwin}
|
||||
var
|
||||
{$IFDEF darwin}
|
||||
F1: CFStringRef;
|
||||
F2: CFStringRef;
|
||||
Flags: CFStringCompareFlags;
|
||||
{$ELSE}
|
||||
File1, File2: string;
|
||||
Len1: SizeInt;
|
||||
Len2: SizeInt;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
begin
|
||||
if (Filename1=nil) or (Filename1^=#0) then begin
|
||||
if (Filename2=nil) or (Filename2^=#0) then begin
|
||||
@ -356,19 +352,12 @@ begin
|
||||
CFRelease(F1);
|
||||
CFRelease(F2);
|
||||
{$ELSE}
|
||||
if IgnoreCase then begin
|
||||
// compare case insensitive
|
||||
Len1:=StrLen(Filename1);
|
||||
SetLength(File1,Len1);
|
||||
System.Move(Filename1^,File1[1],Len1);
|
||||
Len2:=StrLen(Filename2);
|
||||
SetLength(File2,Len2);
|
||||
System.Move(Filename2^,File2[1],Len2);
|
||||
Result:=UTF8CompareText(File1,File2);
|
||||
end else begin
|
||||
if IgnoreCase then // compare case insensitive
|
||||
Result:=UTF8CompareTextP(Filename1, Filename2)
|
||||
else begin
|
||||
// compare literally
|
||||
while (Filename1^=Filename2^) and (Filename1^<>#0) do begin
|
||||
inc(Filename1);
|
||||
Inc(Filename1);
|
||||
Inc(Filename2);
|
||||
end;
|
||||
Result:=ord(Filename1^)-ord(Filename2^);
|
||||
|
@ -173,6 +173,7 @@ function UTF8CompareStr(const S1, S2: string): PtrInt; inline;
|
||||
function UTF8CompareStrP(S1, S2: PChar): PtrInt;
|
||||
function UTF8CompareStr(S1: PChar; Count1: SizeInt; S2: PChar; Count2: SizeInt): PtrInt;
|
||||
function UTF8CompareText(const S1, S2: string): PtrInt;
|
||||
function UTF8CompareTextP(S1, S2: PChar): PtrInt;
|
||||
function UTF8CompareLatinTextFast(const S1, S2: String): PtrInt;
|
||||
function UTF8CompareStrCollated(const S1, S2: string): PtrInt; {$IFnDEF ACP_RTL}inline;{$endif}
|
||||
function CompareStrListUTF8LowerCase(List: TStringList; Index1, Index2: Integer): Integer;
|
||||
@ -3400,6 +3401,11 @@ begin
|
||||
Result := WideCompareText(UTF8ToUTF16(S1),UTF8ToUTF16(S2));
|
||||
end;
|
||||
|
||||
function UTF8CompareTextP(S1, S2: PChar): PtrInt;
|
||||
begin
|
||||
Result := WideCompareText(UTF8ToUTF16(S1,StrLen(S1)), UTF8ToUTF16(S2,StrLen(S2)));
|
||||
end;
|
||||
|
||||
function UTF8CompareLatinTextFast(const S1, S2: String): PtrInt;
|
||||
// Like UTF8CompareText but does not return strict alphabetical order.
|
||||
// The order is deterministic and good for binary search and such uses.
|
||||
|
Loading…
Reference in New Issue
Block a user