16,748
社区成员
发帖
与我相关
我的任务
分享
function GetDomainRoot(url: string): string;
//获得一个URL地址的域
var p1:integer;
begin
//http://user:pass@www.163.com:8080/music/chs/index.aspx?mid=23081712
// p1
result:='';
if LeastUrlRequest(url) then//检验URL是否合法,判断是否含有,{<>这一类的字符
begin
//去掉协议
p1:=pos('://',url);
if (p1>0) then
Delete(url,1,p1+2);
p1:=pos('/',url);
if (p1>1) then
begin
//得到主机地址user:pass@www.163.com:8080
url:=Copy(url,1,p1-1);
if url<>'' then
begin
//去掉用户名和密码www.163.com:8080
p1:=pos('@',url);
if (p1>0) then
Delete(url,1,p1);
//去掉端口www.163.com
Delete(url,pos(':',url),Length(url));
end;
if (pos('192.168.',url)>0) or (NCpos('localhost',url)>0) or (Pos('.',url)<=0) then//局域网的不要
result:=''
else
result:=url;
end else if (length(url)>=3) and (url[1]<>'/') then //a.b满足域名或文件名的形式
result:=url;
end;
end;
function TRegExpr.ExecPrim (AOffset: integer) : boolean;
procedure ClearMatchs;
// Clears matchs array
var i : integer;
begin
for i := 0 to NSUBEXP - 1 do begin
startp [i] := nil;
endp [i] := nil;
end;
end; { of procedure ClearMatchs;
..............................................................}
function RegMatch (str : PRegExprChar) : boolean;
// try match at specific point
begin
//###0.949 removed clearing of start\endp
reginput := str;
Result := MatchPrim (programm + REOpSz);
if Result then begin
startp [0] := str;
endp [0] := reginput;
end;
end; { of function RegMatch
..............................................................}
var
s : PRegExprChar;
StartPtr: PRegExprChar;
InputLen : integer;
begin
Result := false; // Be paranoid...
ClearMatchs; //###0.949
// ensure that Match cleared either if optimization tricks or some error
// will lead to leaving ExecPrim without actual search. That is
// importent for ExecNext logic and so on.
if not IsProgrammOk //###0.929
then EXIT;
// Check InputString presence
if not Assigned (fInputString) then begin
Error (reeNoInpitStringSpecified);
EXIT;
end;
InputLen := length (fInputString);
//Check that the start position is not negative
if AOffset < 1 then begin
Error (reeOffsetMustBeGreaterThen0);
EXIT;
end;
// Check that the start position is not longer than the line
// If so then exit with nothing found
if AOffset > (InputLen + 1) // for matching empty string after last char.
then EXIT;
StartPtr := fInputString + AOffset - 1;
// If there is a "must appear" string, look for it.
if regmust <> nil then begin
s := StartPtr;
REPEAT
s := StrScan (s, regmust [0]);
if s <> nil then begin
if StrLComp (s, regmust, regmlen) = 0
then BREAK; // Found it.
inc (s);
end;
UNTIL s = nil;
if s = nil // Not present.
then EXIT;
end;
// Mark beginning of line for ^ .
fInputStart := fInputString;
// Pointer to end of input stream - for
// pascal-style string processing (may include #0)
fInputEnd := fInputString + InputLen;
{$IFDEF ComplexBraces}
// no loops started
LoopStackIdx := 0; //###0.925
{$ENDIF}
// Simplest case: anchored match need be tried only once.
if reganch <> #0 then begin
Result := RegMatch (StartPtr);
EXIT;
end;
// Messy cases: unanchored match.
s := StartPtr;
if regstart <> #0 then // We know what char it must start with.
REPEAT
s := StrScan (s, regstart);
if s <> nil then begin
Result := RegMatch (s);
if Result
then EXIT
else ClearMatchs; //###0.949
inc (s);
end;
UNTIL s = nil
else begin // We don't - general case.
repeat //###0.948
{$IFDEF UseFirstCharSet}
if s^ in FirstCharSet
then Result := RegMatch (s);
{$ELSE}
Result := RegMatch (s);
{$ENDIF}
if Result or (s^ = #0) // Exit on a match or after testing the end-of-string.
then EXIT
else ClearMatchs; //###0.949
inc (s);
until false;
(* optimized and fixed by Martin Fuller - empty strings
were not allowed to pass thru in UseFirstCharSet mode
{$IFDEF UseFirstCharSet} //###0.929
while s^ <> #0 do begin
if s^ in FirstCharSet
then Result := RegMatch (s);
if Result
then EXIT;
inc (s);
end;
{$ELSE}
REPEAT
Result := RegMatch (s);
if Result
then EXIT;
inc (s);
UNTIL s^ = #0;
{$ENDIF}
*)
end;
// Failure
end; { of function TRegExpr.ExecPrim