URLEncode и URLDecode в Delphi

Написал Lex Luthor, в Статьи » Delphi.
function DigitToHex(Digit: Integer): Char;
begin
case Digit of
0..9: Result := Chr(Digit + Ord('0'));
10..15: Result := Chr(Digit - 10 + Ord('A'));
else
Result := '0';
end;
end; // DigitToHex
function URLEncode(const S: string): string;
var
i, idx, len: Integer;
begin
len := 0;
for i := 1 to Length(S) do
if ((S[i] >= '0') and (S[i] <= '9')) or
((S[i] >= 'A') and (S[i] <= 'Z')) or
((S[i] >= 'a') and (S[i] <= 'z')) or (S[i] = ' ') or
(S[i] = '_') or (S[i] = '*') or (S[i] = '-') or (S[i] = '.') then
len := len + 1
else
len := len + 3;
SetLength(Result, len);
idx := 1;
for i := 1 to Length(S) do
if S[i] = ' ' then
begin
Result[idx] := '+';
idx := idx + 1;
end
else if ((S[i] >= '0') and (S[i] <= '9')) or
((S[i] >= 'A') and (S[i] <= 'Z')) or
((S[i] >= 'a') and (S[i] <= 'z')) or
(S[i] = '_') or (S[i] = '*') or (S[i] = '-') or (S[i] = '.') then
begin
Result[idx] := S[i];
idx := idx + 1;
end
else
begin
Result[idx] := '%';
Result[idx + 1] := DigitToHex(Ord(S[i]) div 16);
Result[idx + 2] := DigitToHex(Ord(S[i]) mod 16);
idx := idx + 3;
end;
end; // URLEncode
function URLDecode(const S: string): string;
var
i, idx, len, n_coded: Integer;
function WebHexToInt(HexChar: Char): Integer;
begin
if HexChar < '0' then
Result := Ord(HexChar) + 256 - Ord('0')
else if HexChar <= Chr(Ord('A') - 1) then
Result := Ord(HexChar) - Ord('0')
else if HexChar <= Chr(Ord('a') - 1) then
Result := Ord(HexChar) - Ord('A') + 10
else
Result := Ord(HexChar) - Ord('a') + 10;
end;
begin
len := 0;
n_coded := 0;
for i := 1 to Length(S) do
if n_coded >= 1 then
begin
n_coded := n_coded + 1;
if n_coded >= 3 then
n_coded := 0;
end
else
begin
len := len + 1;
if S[i] = '%' then
n_coded := 1;
end;
SetLength(Result, len);
idx := 0;
n_coded := 0;
for i := 1 to Length(S) do
if n_coded >= 1 then
begin
n_coded := n_coded + 1;
if n_coded >= 3 then
begin
Result[idx] := Chr((WebHexToInt(S[i - 1]) * 16 +
WebHexToInt(S[i])) mod 256);
n_coded := 0;
end;
end
else
begin
idx := idx + 1;
if S[i] = '%' then
n_coded := 1;
if S[i] = '+' then
Result[idx] := ' '
else
Result[idx] := S[i];
end;
end; // URLDecode
#1 Allex |  

брр.. зачем так усложнять ?
где форматирование кода ?
Дата публикации: 24 декабря 2007 22:05 | ICQ: --
цитировать
#2 John Frost |  

И где собственно сам текст? smile или автор настолько суров, что уже и разговаривает только на Дельфи?
Дата публикации: 6 января 2008 17:12 | ICQ: 488251
цитировать
#3 Agent |  

Имхо на ассамблере лутше http://forum.sources.ru/index.php?showto
pic=70068
Дата публикации: 11 июня 2008 13:18 | ICQ: --
цитировать
#4 styfer |  

Прочитано, принято, понято :) то что искал)
Не в обиду владельцу сайта, но ИМХО, над дизайном стоило бы поработать чуть подольше и поусерднее. Всё-таки внешний вид сайта играет немаловажную роль. Могу судить по личному опыту: после того как-на [url=http://rem-stroy.com/]моём[/url] сайте был нарисован и свёрстан новый диз, читатели стали задерживаться гораздо надольше, да и самому приятно смотреть. Подумайте над этим, думаю моё мнение разделят многие..
Дата публикации: 28 августа 2010 23:27 | ICQ: --
цитировать
#5 vino |  

Если уж заморачиваться на скорость, то пара предложений:
=вместо функции DigitToHex сделать массив DigitToHex[0..15]of char
=зарезервировать без первого цикла SetLength(Result, Length(S)*3);
затем после основного цикла сделать SetLength(Result, idx);
Дата публикации: 30 ноября 2010 17:58 | ICQ: --
цитировать


uses HttpApp


strok:=HttpEncode(strok);
Дата публикации: 2 января 2011 19:17 | ICQ: --
цитировать
#7 bedfreezxc |  

Everyone involved advertising online knows that backlink building is an essential section of success. There are numerous link building instruments available on the market, plus the list continues to grow given that incoming inbound links are so crucial that you the life bloodstream of an on the net presence. You are able to build backlinks to your website by yourself, use link-building software as well as outsource the whole job.

<a href="http://xrumerblasts.in/">xrumer</a
>
http://xrumerblasts.in/
Дата публикации: 19 июня 2011 10:23 | ICQ: --
цитировать

Добавить комментарий


Включите эту картинку для отображения кода безопасности
обновить код



 

Лучшие новости

Наш опрос

Мы в интернете