2008-04-23 23:26:50 +03:00
|
|
|
{==============================================================================|
|
2008-04-24 10:09:13 +03:00
|
|
|
| Project : Delphree - Synapse | 002.003.000 |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| Content: support procedures and functions |
|
|
|
|
|==============================================================================|
|
2008-04-24 10:05:26 +03:00
|
|
|
| The contents of this file are subject to the Mozilla Public License Ver. 1.1 |
|
2008-04-23 23:26:50 +03:00
|
|
|
| (the "License"); you may not use this file except in compliance with the |
|
2008-04-24 10:05:26 +03:00
|
|
|
| License. You may obtain a Copy of the License at http://www.mozilla.org/MPL/ |
|
2008-04-23 23:26:50 +03:00
|
|
|
| |
|
|
|
|
| Software distributed under the License is distributed on an "AS IS" basis, |
|
|
|
|
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for |
|
|
|
|
| the specific language governing rights and limitations under the License. |
|
|
|
|
|==============================================================================|
|
|
|
|
| The Original Code is Synapse Delphi Library. |
|
|
|
|
|==============================================================================|
|
|
|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
2008-04-24 09:42:13 +03:00
|
|
|
| Portions created by Lukas Gebauer are Copyright (c) 1999,2000,2001. |
|
2008-04-23 23:32:54 +03:00
|
|
|
| Portions created by Hernan Sanchez are Copyright (c) 2000. |
|
2008-04-23 23:26:50 +03:00
|
|
|
| All Rights Reserved. |
|
|
|
|
|==============================================================================|
|
|
|
|
| Contributor(s): |
|
2008-04-23 23:32:54 +03:00
|
|
|
| Hernan Sanchez (hernan.sanchez@iname.com) |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| History: see HISTORY.HTM from distribution package |
|
2008-04-23 23:48:39 +03:00
|
|
|
| (Found at URL: http://www.ararat.cz/synapse/) |
|
2008-04-23 23:26:50 +03:00
|
|
|
|==============================================================================}
|
|
|
|
|
2008-04-24 10:00:43 +03:00
|
|
|
{$Q-}
|
|
|
|
|
2008-04-23 23:26:50 +03:00
|
|
|
unit SynaUtil;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2008-04-24 10:05:26 +03:00
|
|
|
SysUtils, Classes,
|
2008-04-24 09:59:26 +03:00
|
|
|
{$IFDEF LINUX}
|
2008-04-24 10:05:26 +03:00
|
|
|
Libc;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$ELSE}
|
2008-04-24 10:05:26 +03:00
|
|
|
Windows;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$ENDIF}
|
2008-04-23 23:26:50 +03:00
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function Timezone: string;
|
|
|
|
function Rfc822DateTime(t: TDateTime): string;
|
2008-04-24 10:09:13 +03:00
|
|
|
function CDateTime(t: TDateTime): string;
|
2008-04-24 10:05:26 +03:00
|
|
|
function CodeInt(Value: Word): string;
|
|
|
|
function DecodeInt(const Value: string; Index: Integer): Word;
|
|
|
|
function IsIP(const Value: string): Boolean;
|
|
|
|
function ReverseIP(Value: string): string;
|
2008-04-24 10:09:13 +03:00
|
|
|
function IPToID(Host: string): string;
|
2008-04-24 10:05:26 +03:00
|
|
|
procedure Dump(const Buffer, DumpFile: string);
|
|
|
|
function SeparateLeft(const Value, Delimiter: string): string;
|
|
|
|
function SeparateRight(const Value, Delimiter: string): string;
|
|
|
|
function GetParameter(const Value, Parameter: string): string;
|
|
|
|
function GetEmailAddr(const Value: string): string;
|
|
|
|
function GetEmailDesc(Value: string): string;
|
|
|
|
function StrToHex(const Value: string): string;
|
|
|
|
function IntToBin(Value: Integer; Digits: Byte): string;
|
|
|
|
function BinToInt(const Value: string): Integer;
|
|
|
|
function ParseURL(URL: string; var Prot, User, Pass, Host, Port, Path,
|
|
|
|
Para: string): string;
|
|
|
|
function StringReplace(Value, Search, Replace: string): string;
|
2008-04-24 10:07:45 +03:00
|
|
|
function RPos(const Sub, Value: String): Integer;
|
|
|
|
function Fetch(var Value: string; const Delimiter: string): string;
|
2008-04-23 23:26:50 +03:00
|
|
|
|
|
|
|
implementation
|
2008-04-24 10:09:13 +03:00
|
|
|
{==============================================================================}
|
|
|
|
var
|
|
|
|
SaveDayNames: array[1..7] of string;
|
|
|
|
SaveMonthNames: array[1..12] of string;
|
|
|
|
const
|
|
|
|
MyDayNames: array[1..7] of string =
|
|
|
|
('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
|
|
|
|
MyMonthNames: array[1..12] of string =
|
|
|
|
('Jan', 'Feb', 'Mar', 'Apr',
|
|
|
|
'May', 'Jun', 'Jul', 'Aug',
|
|
|
|
'Sep', 'Oct', 'Nov', 'Dec');
|
|
|
|
|
|
|
|
procedure SaveNames;
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
|
|
|
for I := Low(ShortDayNames) to High(ShortDayNames) do
|
|
|
|
begin
|
|
|
|
SaveDayNames[I] := ShortDayNames[I];
|
|
|
|
ShortDayNames[I] := MyDayNames[I];
|
|
|
|
end;
|
|
|
|
for I := Low(ShortMonthNames) to High(ShortMonthNames) do
|
|
|
|
begin
|
|
|
|
SaveMonthNames[I] := ShortMonthNames[I];
|
|
|
|
ShortMonthNames[I] := MyMonthNames[I];
|
|
|
|
end;
|
|
|
|
end;
|
2008-04-23 23:26:50 +03:00
|
|
|
|
2008-04-24 10:09:13 +03:00
|
|
|
procedure RestoreNames;
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
|
|
|
for I := Low(ShortDayNames) to High(ShortDayNames) do
|
|
|
|
ShortDayNames[I] := SaveDayNames[I];
|
|
|
|
for I := Low(ShortMonthNames) to High(ShortMonthNames) do
|
|
|
|
ShortMonthNames[I] := SaveMonthNames[I];
|
|
|
|
end;
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function Timezone: string;
|
2008-04-24 09:59:26 +03:00
|
|
|
{$IFDEF LINUX}
|
|
|
|
var
|
|
|
|
t: TTime_T;
|
2008-04-24 10:05:26 +03:00
|
|
|
UT: TUnixTime;
|
|
|
|
bias: Integer;
|
|
|
|
h, m: Integer;
|
2008-04-24 09:59:26 +03:00
|
|
|
begin
|
|
|
|
__time(@T);
|
2008-04-24 10:05:26 +03:00
|
|
|
localtime_r(@T, UT);
|
|
|
|
bias := ut.__tm_gmtoff div 60;
|
|
|
|
if bias >= 0 then
|
|
|
|
Result := '+'
|
|
|
|
else
|
|
|
|
Result := '-';
|
|
|
|
{$ELSE}
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
zoneinfo: TTimeZoneInformation;
|
|
|
|
bias: Integer;
|
|
|
|
h, m: Integer;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-23 23:46:58 +03:00
|
|
|
case GetTimeZoneInformation(Zoneinfo) of
|
2008-04-24 10:05:26 +03:00
|
|
|
2:
|
|
|
|
bias := zoneinfo.Bias + zoneinfo.DaylightBias;
|
|
|
|
1:
|
|
|
|
bias := zoneinfo.Bias + zoneinfo.StandardBias;
|
|
|
|
else
|
|
|
|
bias := zoneinfo.Bias;
|
2008-04-23 23:46:58 +03:00
|
|
|
end;
|
2008-04-24 10:05:26 +03:00
|
|
|
if bias <= 0 then
|
|
|
|
Result := '+'
|
|
|
|
else
|
|
|
|
Result := '-';
|
2008-04-24 09:59:26 +03:00
|
|
|
{$ENDIF}
|
2008-04-24 10:05:26 +03:00
|
|
|
bias := Abs(bias);
|
|
|
|
h := bias div 60;
|
|
|
|
m := bias mod 60;
|
|
|
|
Result := Result + Format('%.2d%.2d', [h, m]);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function Rfc822DateTime(t: TDateTime): string;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:09:13 +03:00
|
|
|
SaveNames;
|
|
|
|
try
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := FormatDateTime('ddd, d mmm yyyy hh:mm:ss', t);
|
2008-04-24 10:09:13 +03:00
|
|
|
Result := Result + ' ' + Timezone;
|
|
|
|
finally
|
|
|
|
RestoreNames;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function CDateTime(t: TDateTime): string;
|
|
|
|
begin
|
|
|
|
SaveNames;
|
|
|
|
try
|
|
|
|
Result := FormatDateTime('mmm dd hh:mm:ss', t);
|
|
|
|
if Result[5] = '0' then
|
|
|
|
Result[5] := ' ';
|
|
|
|
finally
|
|
|
|
RestoreNames;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function CodeInt(Value: Word): string;
|
2008-04-23 23:28:55 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := Chr(Hi(Value)) + Chr(Lo(Value))
|
2008-04-23 23:28:55 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function DecodeInt(const Value: string; Index: Integer): Word;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, y: Byte;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if Length(Value) > Index then
|
|
|
|
x := Ord(Value[Index])
|
|
|
|
else
|
|
|
|
x := 0;
|
2008-04-24 10:09:13 +03:00
|
|
|
if Length(Value) >= (Index + 1) then
|
2008-04-24 10:05:26 +03:00
|
|
|
y := Ord(Value[Index + 1])
|
|
|
|
else
|
|
|
|
y := 0;
|
|
|
|
Result := x * 256 + y;
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function IsIP(const Value: string): Boolean;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n, x: Integer;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := true;
|
|
|
|
x := 0;
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
if not (Value[n] in ['0'..'9', '.']) then
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
Break;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if Value[n] = '.' then
|
|
|
|
Inc(x);
|
|
|
|
end;
|
|
|
|
if x <> 3 then
|
|
|
|
Result := False;
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
function ReverseIP(Value: string): string;
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
2008-04-23 23:26:50 +03:00
|
|
|
repeat
|
2008-04-24 10:05:26 +03:00
|
|
|
x := LastDelimiter('.', Value);
|
|
|
|
Result := Result + '.' + Copy(Value, x + 1, Length(Value) - x);
|
|
|
|
Delete(Value, x, Length(Value) - x + 1);
|
|
|
|
until x < 1;
|
|
|
|
if Length(Result) > 0 then
|
|
|
|
if Result[1] = '.' then
|
2008-04-23 23:32:54 +03:00
|
|
|
Delete(Result, 1, 1);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:09:13 +03:00
|
|
|
{==============================================================================}
|
|
|
|
//Hernan Sanchez
|
|
|
|
function IPToID(Host: string): string;
|
|
|
|
var
|
|
|
|
s, t: string;
|
|
|
|
i, x: Integer;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
for x := 1 to 3 do
|
|
|
|
begin
|
|
|
|
t := '';
|
|
|
|
s := StrScan(PChar(Host), '.');
|
|
|
|
t := Copy(Host, 1, (Length(Host) - Length(s)));
|
|
|
|
Delete(Host, 1, (Length(Host) - Length(s) + 1));
|
|
|
|
i := StrToIntDef(t, 0);
|
|
|
|
Result := Result + Chr(i);
|
|
|
|
end;
|
|
|
|
i := StrToIntDef(Host, 0);
|
|
|
|
Result := Result + Chr(i);
|
|
|
|
end;
|
|
|
|
|
2008-04-23 23:28:55 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
procedure Dump(const Buffer, DumpFile: string);
|
2008-04-23 23:26:50 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
|
|
|
s: string;
|
|
|
|
f: Text;
|
2008-04-23 23:26:50 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
s := '';
|
|
|
|
for n := 1 to Length(Buffer) do
|
|
|
|
s := s + ' +#$' + IntToHex(Ord(Buffer[n]), 2);
|
|
|
|
AssignFile(f, DumpFile);
|
|
|
|
if FileExists(DumpFile) then
|
|
|
|
DeleteFile(PChar(DumpFile));
|
|
|
|
Rewrite(f);
|
2008-04-23 23:26:50 +03:00
|
|
|
try
|
2008-04-24 10:05:26 +03:00
|
|
|
Writeln(f, s);
|
2008-04-23 23:26:50 +03:00
|
|
|
finally
|
2008-04-24 10:05:26 +03:00
|
|
|
CloseFile(f);
|
2008-04-23 23:26:50 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-23 23:48:39 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function SeparateLeft(const Value, Delimiter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(Delimiter, Value);
|
|
|
|
if x < 1 then
|
|
|
|
Result := Trim(Value)
|
|
|
|
else
|
|
|
|
Result := Trim(Copy(Value, 1, x - 1));
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function SeparateRight(const Value, Delimiter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(Delimiter, Value);
|
|
|
|
if x > 0 then
|
|
|
|
x := x + Length(Delimiter) - 1;
|
|
|
|
Result := Trim(Copy(Value, x + 1, Length(Value) - x));
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function GetParameter(const Value, Parameter: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, x1: Integer;
|
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
x := Pos(UpperCase(Parameter), UpperCase(Value));
|
|
|
|
Result := '';
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
s := Copy(Value, x + Length(Parameter), Length(Value)
|
|
|
|
- (x + Length(Parameter)) + 1);
|
|
|
|
s := Trim(s);
|
|
|
|
x1 := Length(s);
|
|
|
|
if Length(s) > 1 then
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if s[1] = '"' then
|
|
|
|
begin
|
|
|
|
s := Copy(s, 2, Length(s) - 1);
|
|
|
|
x := Pos('"', s);
|
|
|
|
if x > 0 then
|
|
|
|
x1 := x - 1;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
x := Pos(' ', s);
|
|
|
|
if x > 0 then
|
|
|
|
x1 := x - 1;
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := Copy(s, 1, x1);
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function GetEmailAddr(const Value: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
s := SeparateRight(Value, '<');
|
|
|
|
s := SeparateLeft(s, '>');
|
|
|
|
Result := Trim(s);
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function GetEmailDesc(Value: string): string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
s: string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Value := Trim(Value);
|
|
|
|
s := SeparateRight(Value, '"');
|
|
|
|
if s <> Value then
|
|
|
|
s := SeparateLeft(s, '"')
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
s := SeparateRight(Value, '(');
|
|
|
|
if s <> Value then
|
|
|
|
s := SeparateLeft(s, ')')
|
2008-04-23 23:48:39 +03:00
|
|
|
else
|
2008-04-24 10:05:26 +03:00
|
|
|
begin
|
|
|
|
s := SeparateLeft(Value, '<');
|
|
|
|
if s = Value then
|
|
|
|
s := '';
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
Result := Trim(s);
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:49:43 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function StrToHex(const Value: string): string;
|
2008-04-23 23:49:43 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
2008-04-23 23:49:43 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
Result := Result + IntToHex(Byte(Value[n]), 2);
|
|
|
|
Result := LowerCase(Result);
|
2008-04-23 23:49:43 +03:00
|
|
|
end;
|
2008-04-24 09:40:58 +03:00
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function IntToBin(Value: Integer; Digits: Byte): string;
|
2008-04-24 09:40:58 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, y, n: Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := '';
|
|
|
|
x := Value;
|
2008-04-24 09:40:58 +03:00
|
|
|
repeat
|
2008-04-24 10:05:26 +03:00
|
|
|
y := x mod 2;
|
|
|
|
x := x div 2;
|
|
|
|
if y > 0 then
|
|
|
|
Result := '1' + Result
|
|
|
|
else
|
|
|
|
Result := '0' + Result;
|
|
|
|
until x = 0;
|
|
|
|
x := Length(Result);
|
|
|
|
for n := x to Digits - 1 do
|
|
|
|
Result := '0' + Result;
|
2008-04-24 09:40:58 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function BinToInt(const Value: string): Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
n: Integer;
|
2008-04-24 09:40:58 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Result := 0;
|
|
|
|
for n := 1 to Length(Value) do
|
|
|
|
begin
|
|
|
|
if Value[n] = '0' then
|
|
|
|
Result := Result * 2
|
|
|
|
else
|
|
|
|
if Value[n] = '1' then
|
|
|
|
Result := Result * 2 + 1
|
|
|
|
else
|
|
|
|
Break;
|
|
|
|
end;
|
2008-04-24 09:40:58 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 09:42:13 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function ParseURL(URL: string; var Prot, User, Pass, Host, Port, Path,
|
|
|
|
Para: string): string;
|
2008-04-24 09:42:13 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x: Integer;
|
|
|
|
sURL: string;
|
|
|
|
s: string;
|
|
|
|
s1, s2: string;
|
2008-04-24 09:42:13 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
Prot := 'http';
|
|
|
|
User := '';
|
|
|
|
Pass := '';
|
|
|
|
Port := '80';
|
|
|
|
Para := '';
|
|
|
|
|
|
|
|
x := Pos('://', URL);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Prot := SeparateLeft(URL, '://');
|
|
|
|
sURL := SeparateRight(URL, '://');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sURL := URL;
|
|
|
|
x := Pos('@', sURL);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
s := SeparateLeft(sURL, '@');
|
|
|
|
sURL := SeparateRight(sURL, '@');
|
|
|
|
x := Pos(':', s);
|
|
|
|
if x > 0 then
|
2008-04-24 09:42:13 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
User := SeparateLeft(s, ':');
|
|
|
|
Pass := SeparateRight(s, ':');
|
2008-04-24 09:42:13 +03:00
|
|
|
end
|
|
|
|
else
|
2008-04-24 10:05:26 +03:00
|
|
|
User := s;
|
|
|
|
end;
|
|
|
|
x := Pos('/', sURL);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
s1 := SeparateLeft(sURL, '/');
|
|
|
|
s2 := SeparateRight(sURL, '/');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
s1 := sURL;
|
|
|
|
s2 := '';
|
|
|
|
end;
|
|
|
|
x := Pos(':', s1);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Host := SeparateLeft(s1, ':');
|
|
|
|
Port := SeparateRight(s1, ':');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Host := s1;
|
|
|
|
Result := '/' + s2;
|
|
|
|
x := Pos('?', s2);
|
|
|
|
if x > 0 then
|
|
|
|
begin
|
|
|
|
Path := '/' + SeparateLeft(s2, '?');
|
|
|
|
Para := SeparateRight(s2, '?');
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Path := '/' + s2;
|
|
|
|
if Host = '' then
|
|
|
|
Host := 'localhost';
|
2008-04-24 09:42:13 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 09:46:22 +03:00
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
function StringReplace(Value, Search, Replace: string): string;
|
2008-04-24 09:46:22 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
x, l, ls, lr: Integer;
|
2008-04-24 09:46:22 +03:00
|
|
|
begin
|
2008-04-24 10:05:26 +03:00
|
|
|
if (Value = '') or (Search = '') then
|
|
|
|
begin
|
|
|
|
Result := Value;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
ls := Length(Search);
|
|
|
|
lr := Length(Replace);
|
|
|
|
Result := '';
|
|
|
|
x := Pos(Search, Value);
|
|
|
|
while x > 0 do
|
|
|
|
begin
|
|
|
|
l := Length(Result);
|
|
|
|
SetLength(Result, l + x - 1);
|
|
|
|
Move(Pointer(Value)^, Pointer(@Result[l + 1])^, x - 1);
|
|
|
|
// Result:=Result+Copy(Value,1,x-1);
|
|
|
|
l := Length(Result);
|
|
|
|
SetLength(Result, l + lr);
|
|
|
|
Move(Pointer(Replace)^, Pointer(@Result[l + 1])^, lr);
|
|
|
|
// Result:=Result+Replace;
|
|
|
|
Delete(Value, 1, x - 1 + ls);
|
|
|
|
x := Pos(Search, Value);
|
|
|
|
end;
|
|
|
|
Result := Result + Value;
|
2008-04-24 09:46:22 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:07:45 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function RPos(const Sub, Value: String): Integer;
|
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
l: Integer;
|
|
|
|
begin
|
|
|
|
result := 0;
|
|
|
|
l := Length(Sub);
|
|
|
|
for n := Length(Value) - l + 1 downto 1 do
|
|
|
|
begin
|
|
|
|
if Copy(Value, n, l) = Sub then
|
|
|
|
begin
|
|
|
|
result := n;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
function Fetch(var Value: string; const Delimiter: string): string;
|
|
|
|
begin
|
|
|
|
Result := SeparateLeft(Value, Delimiter);
|
|
|
|
Value := SeparateRight(Value, Delimiter);
|
|
|
|
end;
|
|
|
|
|
2008-04-23 23:26:50 +03:00
|
|
|
end.
|