Publish System.MemPos.

This commit is contained in:
Rika Ichinose 2025-02-08 17:22:41 +03:00
parent 9cb6497fae
commit f7f8c9a615
3 changed files with 28 additions and 28 deletions

View File

@ -832,32 +832,6 @@ end;
{$endif FPC_HAS_ANSISTR_COPY}
{$if not defined(FPC_HAS_POS_SHORTSTR_ANSISTR)
or not defined(FPC_HAS_POS_ANSISTR_ANSISTR)}
function Find(needle : PByte; nNeedle : SizeUint; haystack : PByte; nHaystack : SizeUint): SizeInt;
var
p,d,pmaxplus1,iNeedle : SizeUint;
begin
p:=0;
if SizeUint(nNeedle-1)<nHaystack then { (nNeedle > 0) and (nNeedle <= nHaystack) }
begin
pmaxplus1:=nHaystack-nNeedle+1;
iNeedle:=0;
repeat
if iNeedle=0 then
iNeedle:=nNeedle;
dec(iNeedle);
d:=IndexByte(haystack[p+iNeedle],pmaxplus1-p,needle[iNeedle])+1;
inc(p,d);
until (d=0) or (CompareByte(haystack[p-1],needle^,nNeedle)=0);
if d=0 then
p:=0;
end;
result:=SizeInt(p)-1;
end;
{$endif need Find}
{$ifndef FPC_HAS_POS_SHORTSTR_ANSISTR}
{$define FPC_HAS_POS_SHORTSTR_ANSISTR}
Function Pos(Const Substr : ShortString; Const Source : RawByteString; Offset : Sizeint = 1) : SizeInt;
@ -868,7 +842,7 @@ begin
result:=0;
dec(Offset);
if SizeUint(Offset)<SizeUint(nsource) then { (Offset >= 0) and (Offset < nsource) }
result:=Find(@Substr[1],length(Substr),pointer(Source)+Offset,nsource-Offset)+1;
result:=MemPos(PByte(@Substr[1]),length(Substr),PByte(Source)+Offset,nsource-Offset)+1;
if result>0 then
inc(result,Offset);
end;
@ -885,7 +859,7 @@ begin
result:=0;
dec(Offset);
if SizeUint(Offset)<SizeUint(nsource) then { (Offset >= 0) and (Offset < nsource) }
result:=Find(pointer(Substr),length(Substr),pointer(Source)+Offset,nsource-Offset)+1;
result:=MemPos(PByte(Substr),length(Substr),PByte(Source)+Offset,nsource-Offset)+1;
if result>0 then
inc(result,Offset);
end;

View File

@ -671,6 +671,31 @@ end;
{$endif not FPC_SYSTEM_HAS_COMPARECHAR0}
{$ifndef FPC_SYSTEM_HAS_MEMPOS_PBYTE}
function MemPos(needle:PByte;nNeedle:SizeUint;haystack:PByte;nHaystack:SizeUint):SizeInt;
var
p,d,pmaxplus1,iNeedle : SizeUint;
begin
p:=0;
if SizeUint(nNeedle-1)<nHaystack then { (nNeedle > 0) and (nNeedle <= nHaystack) }
begin
pmaxplus1:=nHaystack-nNeedle+1;
iNeedle:=0;
repeat
if iNeedle=0 then
iNeedle:=nNeedle;
dec(iNeedle);
d:=IndexByte(haystack[p+iNeedle],pmaxplus1-p,needle[iNeedle])+1;
inc(p,d);
until (d=0) or (CompareByte(haystack[p-1],needle^,nNeedle)=0);
if d=0 then
p:=0;
end;
result:=SizeInt(p)-1;
end;
{$endif not FPC_SYSTEM_HAS_MEMPOS_PBYTE}
{****************************************************************************
Object Helpers
****************************************************************************}

View File

@ -923,6 +923,7 @@ function CompareDWord(const buf1,buf2;len:SizeInt):SizeInt; {$if defined(cpui38
procedure MoveChar0(const buf1;var buf2;len:SizeInt);
function IndexChar0(const buf;len:SizeInt;b:Ansichar):SizeInt;
function CompareChar0(const buf1,buf2;len:SizeInt):SizeInt;
function MemPos(needle:PByte;nNeedle:SizeUint;haystack:PByte;nHaystack:SizeUint):SizeInt;
procedure Prefetch(const mem);[internproc:fpc_in_prefetch_var];
procedure ReadBarrier; {$ifdef SYSTEMINLINE}inline;{$endif}