Registriert seit: 2. Mär 2004
5.508 Beiträge
Delphi 5 Professional
|
Re: Javascript-Funktion in Delphi?
21. Okt 2004, 08:37
Delphi-Quellcode:
function Escape(const value: string): string;
var
pSrcEnd,pSrc: PChar;
pDstBeg,pDst: PChar;
begin
SetLength(Result,Length(value)*3);
if Length(Result) = 0 then
Exit;
pSrc := @Value[1];
pSrcEnd := @Value[Length(value)];
pDst := @Result[1];
pDstBeg := @Result[1];
while pSrc <= pSrcEnd do
begin
if pSrc^ in ['%',#0..#31,#128..#255] then
begin
pDst^ := '%';
Inc(pDst);
BinToHex(pSrc, pDst, 1);
Inc(pDst,2);
end
else
begin
pDst^ := pSrc^;
Inc(pDst);
end;
Inc(pSrc);
end;
SetLength(Result,pDst-pDstBeg);
end;
function UnEscape(const Value: string): string;
var
pSrc,pSrcEnd: PChar;
pDst,pDstBeg: PChar;
begin
SetLength(Result,Length(Value));
if Length(Result) = 0 then
Exit;
pSrc := @Value[1];
pSrcEnd := @Value[Length(Value)];
pDstBeg := @Result[1];
pDst := @Result[1];
while pSrc <= pSrcEnd do
begin
if pSrc^ = '%' then
begin
Inc(pSrc);
HexToBin(pSrc,pDst,2);
Inc(pSrc,2);
end
else
begin
pDst^ := pSrc^;
Inc(pSrc);
end;
Inc(pDst);
end;
SetLength(Result,pDst-pDstBeg);
end;
Andreas
|
|
Zitat
|