This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.



Test cases

   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".
   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".


function urlDecode(data: String): AnsiString;
var
  ch: Char;
  pos, skip: Integer;
 
begin
  pos := 0;
  skip := 0;
  Result := '';
 
  for ch in data do begin
    if skip = 0 then begin
      if (ch = '%') and (pos < data.length -2) then begin
        skip := 2;
        Result := Result + AnsiChar(Hex2Dec('$' + data[pos+2] + data[pos+3]));
 
      end else begin
        Result := Result + ch;
      end;
 
    end else begin
      skip := skip - 1;
    end;
    pos := pos +1;
  end;
end;