Heb je hier iets aan ?
Code:
unit DzURL;
{ By Alexander Dzyubenko
alexander@dzsoft.com
http://www.dzsoft.com }
interface
uses SysUtils;
function UrlEncode(const DecodedStr: String; Pluses: Boolean): String;
// Encodes standard string into URL data format.
// Example: http://www.dzsoft.com -> http%3A%2F%2Fwww.dzsoft.com%2F
// Pluses parameter specifies whether spaces will be
// encoded as '+' or as '%20'
function UrlDecode(const EncodedStr: String): String;
// Decodes URL data into a readable string.
// Example: http%3A%2F%2Fwww.dzsoft.com%2F -> http://www.dzsoft.com
function HexToInt(HexStr: String): Int64;
// Taken from http://www.delphi3000.com/article.asp?id=1412
implementation
function UrlEncode(const DecodedStr: String; Pluses: Boolean): String;
var
I: Integer;
begin
Result := '';
if Length(DecodedStr) > 0 then
for I := 1 to Length(DecodedStr) do
begin
if not (DecodedStr[I] in ['0'..'9', 'a'..'z',
'A'..'Z', ' ']) then
Result := Result + '%' + IntToHex(Ord(DecodedStr[I]), 2)
else if not (DecodedStr[I] = ' ') then
Result := Result + DecodedStr[I]
else
begin
if not Pluses then
Result := Result + '%20'
else
Result := Result + '+';
end;
end;
end;
function UrlDecode(const EncodedStr: String): String;
var
I: Integer;
begin
Result := '';
if Length(EncodedStr) > 0 then
begin
I := 1;
while I <= Length(EncodedStr) do
begin
if EncodedStr[I] = '%' then
begin
Result := Result + Chr(HexToInt(EncodedStr[I+1]
+ EncodedStr[I+2]));
I := Succ(Succ(I));
end
else if EncodedStr[I] = '+' then
Result := Result + ' '
else
Result := Result + EncodedStr[I];
I := Succ(I);
end;
end;
end;
function HexToInt(HexStr: String): Int64;
var RetVar : Int64;
i : byte;
begin
HexStr := UpperCase(HexStr);
if HexStr[length(HexStr)] = 'H' then
Delete(HexStr,length(HexStr),1);
RetVar := 0;
for i := 1 to length(HexStr) do begin
RetVar := RetVar shl 4;
if HexStr[i] in ['0'..'9'] then
RetVar := RetVar + (byte(HexStr[i]) - 48)
else
if HexStr[i] in ['A'..'F'] then
RetVar := RetVar + (byte(HexStr[i]) - 55)
else begin
Retvar := 0;
break;
end;
end;
Result := RetVar;
end;
end.
Bookmarks