|
@@ -81,6 +81,9 @@ Function MidStr(const AText: WideString; const AStart, ACount: Integer): WideStr
|
|
|
const
|
|
|
{ Default word delimiters are any character except the core alphanumerics. }
|
|
|
WordDelimiters: set of Char = [#0..#255] - ['a'..'z','A'..'Z','1'..'9','0'];
|
|
|
+
|
|
|
+resourcestring
|
|
|
+ SErrAmountStrings = 'Amount of search and replace strings don''t match';
|
|
|
|
|
|
type
|
|
|
TStringSearchOption = (soDown, soMatchCase, soWholeWord);
|
|
@@ -92,6 +95,7 @@ Function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; Se
|
|
|
Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer;
|
|
|
Function PosEx(const SubStr, S: string): Integer;inline; // Offset: Cardinal = 1
|
|
|
Function PosEx(c:char; const S: string; Offset: Cardinal): Integer;
|
|
|
+function StringsReplace(const S: string; OldPattern, NewPattern: array of string; Flags: TReplaceFlags): string;
|
|
|
|
|
|
{ ---------------------------------------------------------------------
|
|
|
Soundex Functions.
|
|
@@ -198,12 +202,6 @@ implementation
|
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
-Procedure NotYetImplemented (FN : String);
|
|
|
-
|
|
|
-begin
|
|
|
- Raise Exception.CreateFmt('Function "%s" (strutils) is not yet implemented',[FN]);
|
|
|
-end;
|
|
|
-
|
|
|
function Hex2Dec(const S: string): Longint;
|
|
|
var
|
|
|
HexStr: string;
|
|
@@ -669,6 +667,66 @@ begin
|
|
|
{$endif}
|
|
|
end;
|
|
|
|
|
|
+function StringsReplace(const S: string; OldPattern, NewPattern: array of string; Flags: TReplaceFlags): string;
|
|
|
+
|
|
|
+var pc,pcc,lastpc : pchar;
|
|
|
+ strcount : integer;
|
|
|
+ ResStr,
|
|
|
+ CompStr : string;
|
|
|
+ Found : Boolean;
|
|
|
+ sc : integer;
|
|
|
+
|
|
|
+begin
|
|
|
+ sc := length(OldPattern);
|
|
|
+ if sc <> length(NewPattern) then
|
|
|
+ raise exception.Create(SErrAmountStrings);
|
|
|
+
|
|
|
+ dec(sc);
|
|
|
+
|
|
|
+ if rfIgnoreCase in Flags then
|
|
|
+ begin
|
|
|
+ CompStr:=AnsiUpperCase(S);
|
|
|
+ for strcount := 0 to sc do
|
|
|
+ OldPattern[strcount] := AnsiUpperCase(OldPattern[strcount]);
|
|
|
+ end
|
|
|
+ else
|
|
|
+ CompStr := s;
|
|
|
+
|
|
|
+ ResStr := '';
|
|
|
+ pc := @CompStr[1];
|
|
|
+ pcc := @s[1];
|
|
|
+ lastpc := pc+Length(S);
|
|
|
+
|
|
|
+ while pc < lastpc do
|
|
|
+ begin
|
|
|
+ Found := False;
|
|
|
+ for strcount := 0 to sc do
|
|
|
+ begin
|
|
|
+ if (length(OldPattern[strcount])>0) and
|
|
|
+ (OldPattern[strcount][1]=pc^) and
|
|
|
+ (Length(OldPattern[strcount]) <= (lastpc-pc)) and
|
|
|
+ (CompareByte(OldPattern[strcount][1],pc^,Length(OldPattern[strcount]))=0) then
|
|
|
+ begin
|
|
|
+ ResStr := ResStr + NewPattern[strcount];
|
|
|
+ pc := pc+Length(OldPattern[strcount]);
|
|
|
+ pcc := pcc+Length(OldPattern[strcount]);
|
|
|
+ Found := true;
|
|
|
+ end
|
|
|
+ end;
|
|
|
+ if not found then
|
|
|
+ begin
|
|
|
+ ResStr := ResStr + pcc^;
|
|
|
+ inc(pc);
|
|
|
+ inc(pcc);
|
|
|
+ end
|
|
|
+ else if not (rfReplaceAll in Flags) then
|
|
|
+ begin
|
|
|
+ ResStr := ResStr + StrPas(pcc);
|
|
|
+ break;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ Result := ResStr;
|
|
|
+end;
|
|
|
|
|
|
{ ---------------------------------------------------------------------
|
|
|
Soundex Functions.
|