1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
{
Copyright 1998-2018 PasDoc developers.
This file is part of "PasDoc".
"PasDoc" is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"PasDoc" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with "PasDoc"; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
----------------------------------------------------------------------------
}
{ Compatibility unit providing various utilities from
standard StrUtils unit to Delphi 5.
This unit should be compilable only with Delphi 5.
When using Delphi 5, you should add this unit to your unit search
path, and then pasdoc should compile "out of the box".
When compiling pasdoc with newer compilers, you should just use
StrUtils provided by them.
It seems that many people are committed to keeping Delphi 5
compatibility of pasdoc sources --- OK, so you will have to maintain
this unit and make sure that it works with Delphi 5 and allows compiling
pasdoc with Delphi 5.
Many bits in this unit may be copied from FPC StrUtils.pp
implementation (but of course you should make sure that given
implementation compiles and works with Delphi 5).
}
unit StrUtils;
interface
Function IfThen(AValue: Boolean; const ATrue: string; AFalse: string): string; overload;
Function IfThen(AValue: Boolean; const ATrue: string): string; overload; // ; AFalse: string = ''
Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer; overload;
Function PosEx(const SubStr, S: string): Integer; overload; // Offset: Cardinal = 1
Function PosEx(c:char; const S: string; Offset: Cardinal): Integer; overload;
Function DupeString(const AText: string; ACount: Integer): string;
implementation
uses SysUtils;
Function IfThen(AValue: Boolean; const ATrue: string; AFalse: string): string;
begin
if avalue then
result:=atrue
else
result:=afalse;
end;
Function IfThen(AValue: Boolean; const ATrue: string): string; // ; AFalse: string = ''
begin
if avalue then
result:=atrue
else
result:='';
end;
Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer;
var i : pchar;
begin
if (offset<1) or (offset>length(s)) then
begin
Result := 0;
Exit
end;
i:=strpos(@s[offset],@substr[1]);
if i=nil then
PosEx:=0
else
PosEx:=succ(i-pchar(s));
end;
Function PosEx(const SubStr, S: string): Integer; // Offset: Cardinal = 1
begin
posex:=posex(substr,s,1);
end;
Function PosEx(c:char; const S: string; Offset: Cardinal): Integer;
var l : longint;
begin
if (offset<1) or (offset>length(s)) then
begin
Result := 0;
Exit
end;
l:=length(s);
while (offset<=l) and (s[offset]<>c) do inc(offset);
if offset>l then
posex:=0
else
posex:=offset;
end;
Function DupeString(const AText: string; ACount: Integer): string;
var i,l : integer;
begin
result:='';
if aCount>=0 then
begin
l:=length(atext);
SetLength(result,aCount*l);
for i:=0 to ACount-1 do
move(atext[1],Result[l*i+1],l);
end;
end;
end.
|