mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 19:29:24 +02:00
* Added UnicodeStringReplace WideStringReplace (bug ID 28396)
git-svn-id: trunk@32815 -
This commit is contained in:
parent
5852d609b1
commit
244be4f4c2
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9385,6 +9385,7 @@ rtl/objpas/sysutils/sysint.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/sysinth.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/syspch.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/syspchh.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/syssr.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/sysstr.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/sysstrh.inc svneol=native#text/plain
|
||||
rtl/objpas/sysutils/systhrdh.inc svneol=native#text/plain
|
||||
|
36
rtl/objpas/sysutils/syssr.inc
Normal file
36
rtl/objpas/sysutils/syssr.inc
Normal file
@ -0,0 +1,36 @@
|
||||
var
|
||||
Srch,OldP,RemS: SRString; // Srch and Oldp can contain uppercase versions of S,OldPattern
|
||||
P : Integer;
|
||||
begin
|
||||
Srch:=S;
|
||||
OldP:=OldPattern;
|
||||
if rfIgnoreCase in Flags then
|
||||
begin
|
||||
Srch:=SRUpperCase(Srch);
|
||||
OldP:=SRUpperCase(OldP);
|
||||
end;
|
||||
RemS:=S;
|
||||
Result:='';
|
||||
while (Length(Srch)<>0) do
|
||||
begin
|
||||
P:=AnsiPos(OldP, Srch);
|
||||
if P=0 then
|
||||
begin
|
||||
Result:=Result+RemS;
|
||||
Srch:='';
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result:=Result+Copy(RemS,1,P-1)+NewPattern;
|
||||
P:=P+Length(OldP);
|
||||
RemS:=Copy(RemS,P,Length(RemS)-P+1);
|
||||
if not (rfReplaceAll in Flags) then
|
||||
begin
|
||||
Result:=Result+RemS;
|
||||
Srch:='';
|
||||
end
|
||||
else
|
||||
Srch:=Copy(Srch,P,Length(Srch)-P+1);
|
||||
end;
|
||||
end;
|
||||
end;
|
@ -2619,45 +2619,17 @@ begin
|
||||
Dec(Result);
|
||||
end;
|
||||
|
||||
{$macro on}
|
||||
{$define INSTRINGREPLACE}
|
||||
{$define SRString:=String}
|
||||
{$define SRUpperCase:=AnsiUppercase}
|
||||
|
||||
Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
|
||||
var
|
||||
Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
|
||||
P : Integer;
|
||||
begin
|
||||
Srch:=S;
|
||||
OldP:=OldPattern;
|
||||
if rfIgnoreCase in Flags then
|
||||
begin
|
||||
Srch:=AnsiUpperCase(Srch);
|
||||
OldP:=AnsiUpperCase(OldP);
|
||||
end;
|
||||
RemS:=S;
|
||||
Result:='';
|
||||
while (Length(Srch)<>0) do
|
||||
begin
|
||||
P:=AnsiPos(OldP, Srch);
|
||||
if P=0 then
|
||||
begin
|
||||
Result:=Result+RemS;
|
||||
Srch:='';
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result:=Result+Copy(RemS,1,P-1)+NewPattern;
|
||||
P:=P+Length(OldP);
|
||||
RemS:=Copy(RemS,P,Length(RemS)-P+1);
|
||||
if not (rfReplaceAll in Flags) then
|
||||
begin
|
||||
Result:=Result+RemS;
|
||||
Srch:='';
|
||||
end
|
||||
else
|
||||
Srch:=Copy(Srch,P,Length(Srch)-P+1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$i syssr.inc}
|
||||
|
||||
{$undef INSTRINGREPLACE}
|
||||
{$undef SRString}
|
||||
{$undef SRUpperCase}
|
||||
|
||||
Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
|
||||
|
||||
|
@ -532,3 +532,14 @@ function ByteLength(const S: UnicodeString): Integer;
|
||||
begin
|
||||
Result:=Length(S)*SizeOf(UnicodeChar);
|
||||
end;
|
||||
|
||||
{$macro on}
|
||||
{$define INUNICODESTRINGREPLACE}
|
||||
{$define SRString:=UnicodeString}
|
||||
{$define SRUpperCase:=WideUppercase}
|
||||
function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString; Flags: TReplaceFlags): UnicodeString;
|
||||
{$i syssr.inc}
|
||||
|
||||
{$undef INUNICODESTRINGREPLACE}
|
||||
{$undef SRString}
|
||||
{$undef SRUpperCase}
|
||||
|
@ -67,3 +67,4 @@ function StringOf(const Bytes: TBytes): UnicodeString;
|
||||
function WideBytesOf(const Value: UnicodeString): TBytes;
|
||||
function WideStringOf(const Value: TBytes): UnicodeString;
|
||||
function ByteLength(const S: UnicodeString): Integer;
|
||||
function UnicodeStringReplace(const S, OldPattern, NewPattern: UnicodeString; Flags: TReplaceFlags): UnicodeString;
|
||||
|
@ -179,3 +179,14 @@ Function CharInSet(Ch:WideChar;Const CSet : TSysCharSet) : Boolean;
|
||||
begin
|
||||
result:=(Ch<=#$FF) and (ansichar(byte(ch)) in CSet);
|
||||
end;
|
||||
|
||||
{$macro on}
|
||||
{$define INWIDESTRINGREPLACE}
|
||||
{$define SRString:=WideString}
|
||||
{$define SRUpperCase:=WideUppercase}
|
||||
function WideStringReplace(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
|
||||
{$i syssr.inc}
|
||||
|
||||
{$undef INWIDESTRINGREPLACE}
|
||||
{$undef SRString}
|
||||
{$undef SRUpperCase}
|
||||
|
@ -34,3 +34,4 @@ function StrLen(p: pwidechar): sizeint; external name 'FPC_PWIDECHAR_LENGTH'; ov
|
||||
function StrCopy(Dest, Source: PWideChar): PWideChar; overload;
|
||||
function StrLCopy(Dest,Source: PWideChar; MaxLen: SizeInt): PWideChar; overload;
|
||||
Function CharInSet(Ch:WideChar;Const CSet : TSysCharSet) : Boolean;
|
||||
function WideStringReplace(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
|
||||
|
Loading…
Reference in New Issue
Block a user