|
@@ -1632,7 +1632,6 @@ begin
|
|
nextPattern := PSizeInt(nextPatternStatic)
|
|
nextPattern := PSizeInt(nextPatternStatic)
|
|
else
|
|
else
|
|
nextPattern := GetMem(Length(OldPattern) * sizeof(SizeInt));
|
|
nextPattern := GetMem(Length(OldPattern) * sizeof(SizeInt));
|
|
- FillChar(nextPattern^, Length(OldPattern) * sizeof(SizeInt), byte(-1));
|
|
|
|
|
|
|
|
if rfIgnoreCase in Flags then
|
|
if rfIgnoreCase in Flags then
|
|
begin
|
|
begin
|
|
@@ -1674,7 +1673,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
- if nextPattern <> PSizeInt(nextPattern) then
|
|
|
|
|
|
+ if nextPattern <> PSizeInt(nextPatternStatic) then
|
|
FreeMem(nextPattern);
|
|
FreeMem(nextPattern);
|
|
if litStart = PAnsiChar(Pointer(S)) then
|
|
if litStart = PAnsiChar(Pointer(S)) then
|
|
exit(S); // Unchanged string.
|
|
exit(S); // Unchanged string.
|
|
@@ -1892,23 +1891,23 @@ begin
|
|
Result:=DelChars(S,' ');
|
|
Result:=DelChars(S,' ');
|
|
end;
|
|
end;
|
|
|
|
|
|
-function IndexCharSized(p: PChar; nchars: SizeInt; charv: SizeUint): SizeInt; inline;
|
|
|
|
|
|
+function IndexCharType(p: PChar; nchars: SizeInt; ch: Char): SizeInt; inline;
|
|
begin
|
|
begin
|
|
result :=
|
|
result :=
|
|
{$if sizeof(char) = sizeof(byte)} IndexByte
|
|
{$if sizeof(char) = sizeof(byte)} IndexByte
|
|
{$elseif sizeof(char) = sizeof(word)} IndexWord
|
|
{$elseif sizeof(char) = sizeof(word)} IndexWord
|
|
{$else} {$error unknown char size}
|
|
{$else} {$error unknown char size}
|
|
{$endif}
|
|
{$endif}
|
|
- (p^, nchars, charv);
|
|
|
|
|
|
+ (p^, nchars, ord(ch));
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure FillCharSized(p: PChar; nchars: SizeInt; charv: SizeUint); inline;
|
|
|
|
|
|
+procedure FillCharType(p: PChar; nchars: SizeInt; ch: Char); inline;
|
|
begin
|
|
begin
|
|
{$if sizeof(char) = sizeof(byte)} FillChar
|
|
{$if sizeof(char) = sizeof(byte)} FillChar
|
|
{$elseif sizeof(char) = sizeof(word)} FillWord
|
|
{$elseif sizeof(char) = sizeof(word)} FillWord
|
|
{$else} {$error unknown char size}
|
|
{$else} {$error unknown char size}
|
|
{$endif}
|
|
{$endif}
|
|
- (p^, nchars, charv);
|
|
|
|
|
|
+ (p^, nchars, ord(ch));
|
|
end;
|
|
end;
|
|
|
|
|
|
function DelChars(const S: string; Chr: Char): string;
|
|
function DelChars(const S: string; Chr: Char): string;
|
|
@@ -1920,7 +1919,7 @@ var
|
|
begin
|
|
begin
|
|
Sp := PChar(Pointer(S));
|
|
Sp := PChar(Pointer(S));
|
|
Se := Sp + Length(S);
|
|
Se := Sp + Length(S);
|
|
- ToCopy := IndexCharSized(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), ord(Chr));
|
|
|
|
|
|
+ ToCopy := IndexCharType(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), Chr);
|
|
if ToCopy < 0 then
|
|
if ToCopy < 0 then
|
|
exit(S); // Unchanged string.
|
|
exit(S); // Unchanged string.
|
|
SetLength(result, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char));
|
|
SetLength(result, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char));
|
|
@@ -1934,7 +1933,7 @@ begin
|
|
until (Sp >= Se) or (Sp^ <> Chr);
|
|
until (Sp >= Se) or (Sp^ <> Chr);
|
|
if Sp >= Se then
|
|
if Sp >= Se then
|
|
break;
|
|
break;
|
|
- ToCopy := IndexCharSized(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), ord(Chr));
|
|
|
|
|
|
+ ToCopy := IndexCharType(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), Chr);
|
|
if ToCopy < 0 then
|
|
if ToCopy < 0 then
|
|
ToCopy := SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char);
|
|
ToCopy := SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char);
|
|
until false;
|
|
until false;
|
|
@@ -1945,7 +1944,7 @@ function DelChars(const S: string; Chars: TSysCharSet): string;
|
|
|
|
|
|
var
|
|
var
|
|
Ss, Sp, Se, Rp: PChar;
|
|
Ss, Sp, Se, Rp: PChar;
|
|
- aDelta : Integer;
|
|
|
|
|
|
+ aDelta : SizeInt;
|
|
|
|
|
|
begin
|
|
begin
|
|
Ss := PChar(Pointer(S));
|
|
Ss := PChar(Pointer(S));
|
|
@@ -1980,7 +1979,7 @@ var
|
|
SpacePos: SizeInt;
|
|
SpacePos: SizeInt;
|
|
begin
|
|
begin
|
|
repeat
|
|
repeat
|
|
- SpacePos := IndexCharSized(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), ord(' '));
|
|
|
|
|
|
+ SpacePos := IndexCharType(Sp, SizeUint(Pointer(Se) - Pointer(Sp)) div sizeof(Char), ' ');
|
|
if SpacePos < 0 then
|
|
if SpacePos < 0 then
|
|
Exit(Se);
|
|
Exit(Se);
|
|
Inc(Sp, SpacePos+1);
|
|
Inc(Sp, SpacePos+1);
|
|
@@ -2057,7 +2056,7 @@ begin
|
|
if l>=N then
|
|
if l>=N then
|
|
Exit(S);
|
|
Exit(S);
|
|
SetLength(Result,N);
|
|
SetLength(Result,N);
|
|
- FillCharSized(Pointer(Result),N-l,ord(C));
|
|
|
|
|
|
+ FillCharType(Pointer(Result),N-l,Char(C));
|
|
Move(Pointer(S)^,PChar(Pointer(Result))[N-l],l*sizeof(Char));
|
|
Move(Pointer(S)^,PChar(Pointer(Result))[N-l],l*sizeof(Char));
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -2072,7 +2071,7 @@ begin
|
|
Exit(S);
|
|
Exit(S);
|
|
SetLength(Result,N);
|
|
SetLength(Result,N);
|
|
Move(Pointer(S)^,Pointer(Result)^,l*sizeof(Char));
|
|
Move(Pointer(S)^,Pointer(Result)^,l*sizeof(Char));
|
|
- FillCharSized(PChar(Pointer(Result))+l,N-l,ord(C));
|
|
|
|
|
|
+ FillCharType(PChar(Pointer(Result))+l,N-l,Char(C));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -2306,28 +2305,24 @@ end;
|
|
function IsWordPresent(const W, S: string; const WordDelims: TSysCharSet): Boolean;
|
|
function IsWordPresent(const W, S: string; const WordDelims: TSysCharSet): Boolean;
|
|
|
|
|
|
var
|
|
var
|
|
- P,PE,WordStart : PChar;
|
|
|
|
- Wbytes : SizeInt;
|
|
|
|
|
|
+ P,PE : PChar;
|
|
|
|
+ Wn,Sn,Wi : SizeInt;
|
|
|
|
+ Wstartc : Char;
|
|
|
|
|
|
begin
|
|
begin
|
|
- Wbytes:=Length(W)*sizeof(char);
|
|
|
|
- P:=PChar(pointer(S));
|
|
|
|
- PE:=P+Length(S);
|
|
|
|
- while (P<PE) and (P^ in WordDelims) do
|
|
|
|
- Inc(P);
|
|
|
|
- while (P<PE) do
|
|
|
|
- begin
|
|
|
|
- WordStart:=P;
|
|
|
|
- repeat
|
|
|
|
- Inc(P);
|
|
|
|
- until (P>=PE) or (P^ in WordDelims);
|
|
|
|
- if (pointer(P)-pointer(WordStart)=Wbytes) and (CompareByte(Pointer(W)^,WordStart^,Wbytes)=0) then
|
|
|
|
- exit(true);
|
|
|
|
- repeat
|
|
|
|
- Inc(P); // Can increment to PE + 1.
|
|
|
|
- until (P>=PE) or not (P^ in WordDelims);
|
|
|
|
- end;
|
|
|
|
- result:=false;
|
|
|
|
|
|
+ Wn:=Length(W);
|
|
|
|
+ Sn:=Length(S);
|
|
|
|
+ if (Sn=0) or (Wn=0) or (Wn>Sn) then
|
|
|
|
+ exit(false);
|
|
|
|
+ Wstartc:=W[1];
|
|
|
|
+ P:=PChar(pointer(S))-1; { Loop starts with an extra increment. }
|
|
|
|
+ PE:=P+2+Sn-Wn;
|
|
|
|
+ repeat
|
|
|
|
+ P:=P+1;
|
|
|
|
+ Wi:=IndexCharType(P,SizeUint(Pointer(PE)-Pointer(P)) div SizeOf(Char),Wstartc);
|
|
|
|
+ P:=P+Wi;
|
|
|
|
+ until (Wi<0) or ((P=PChar(Pointer(S))) or (P[-1] in WordDelims)) and ((P+1=PE) or (P[Wn] in WordDelims)) and (CompareByte(P^,Pointer(W)^,Wn*SizeOf(Char))=0);
|
|
|
|
+ result:=Wi>=0;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -2357,8 +2352,8 @@ begin
|
|
exit(S);
|
|
exit(S);
|
|
SetLength(Result,Len);
|
|
SetLength(Result,Len);
|
|
Nfirstspaces:=SizeUint(Len) div 2-SizeUint(Ns) div 2;
|
|
Nfirstspaces:=SizeUint(Len) div 2-SizeUint(Ns) div 2;
|
|
- FillCharSized(Pointer(Result),Nfirstspaces,ord(' '));
|
|
|
|
- FillCharSized(PChar(Pointer(Result))+Ns+Nfirstspaces,Len-Ns-Nfirstspaces,ord(' '));
|
|
|
|
|
|
+ FillCharType(Pointer(Result),Nfirstspaces,' ');
|
|
|
|
+ FillCharType(PChar(Pointer(Result))+Ns+Nfirstspaces,Len-Ns-Nfirstspaces,' ');
|
|
Move(Pointer(S)^,PChar(Pointer(Result))[Nfirstspaces],Ns*sizeof(char));
|
|
Move(Pointer(S)^,PChar(Pointer(Result))[Nfirstspaces],Ns*sizeof(char));
|
|
end;
|
|
end;
|
|
|
|
|