comp.lang.ada
 help / color / mirror / Atom feed
From: Marius Amado Alves <amado.alves@netcabo.pt>
To: comp.lang.ada@ada.eu.org
Subject: Re: Unescape URL Procedure
Date: Sat, 16 Oct 2004 11:04:59 +0100
Date: 2004-10-16T11:04:59+01:00	[thread overview]
Message-ID: <mailman.350.1097921096.390.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <000901c4b365$719e8720$0201a8c0@win>

> Does anyone know of an Unescape URL procedure for Ada?

My program Decode_HH does something along this line:

-- It transforms any two hexadecimal digits prefixed by '='
-- into the corresponding character (Latin 1).
-- The first hexadecimal digit must be an uppercase letter.
-- It is a filter (uses standard input and output channels).

The program is published in the SDC forum, area Files / Software:

    http://www.softdevelcoop.org

You must be a member to enter the Files area. Membership is open to all, 
but for your convenience I copy the whole program below.

<<
-- Program Decode_HH
-- Version 1maa (2003-04-01)
-- (C) M�rio Amado Alves

-- ATTENTION: the use of this software is subject to conditions,
-- which the user must know in order to be in a legal state.
-- See bottom of the file.

-- This program restores email-mangled text originally containing Latin 1.
-- It transforms any two hexadecimal digits prefixed by '='
-- into the corresponding character (Latin 1).
-- The first hexadecimal digit must be an uppercase letter.
-- It is a filter (uses standard input and output channels).

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Characters.Handling; use Ada.Characters.Handling;

procedure Decode_HH_1maa is

   T : String (1 .. 3);
   subtype HH_Type is Natural range 0 .. 16#FF#;
   package HH_IO is new Ada.Text_IO.Integer_IO (HH_Type);
   N : HH_Type;
   Dummy_Last: Positive;
   Finish : exception;

   procedure Get (S : out String) is
   begin
     for I in S'Range loop
       begin
         Get_Immediate (S (I));
       exception
         when End_Error =>
           Put (S (S'First .. I - 1));
           raise;
       end;
     end loop;
   end;

begin

   Get (T (1 .. 3));
   loop
     if T (1) = '='
     and then T (2) in 'A' .. 'F'
     and then Is_Hexadecimal_Digit (T (3))
     then
       HH_IO.Get ("16#" & T (2 .. 3) & "#", N, Dummy_Last);
       Put (Character'Val (N));
       Get (T (1 .. 3));
     else
       Put (T (1));
       T (1 .. 2) := T (2 .. 3);
       begin
         Get_Immediate (T (3));
       exception
         when End_Error =>
           Put (T (1 .. 2));
           raise;
       end;
     end if;
   end loop;

exception

   when End_Error => null;

end;

-- REVISION HISTORY
-- 2003-04-01: version 1maa created and tested

-- CONDITIONS OF USE
-- This software is licensed under the terms of the
-- Software Developers Cooperative License, published at
--
--   groups.yahoo.com/group/softdevelcoop
--
-- In short, it is free for non-commercial use,
-- but royalties are due for use in a business.
-- See the website for details and contact information.
 >>




       reply	other threads:[~2004-10-16 10:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <000901c4b365$719e8720$0201a8c0@win>
2004-10-16 10:04 ` Marius Amado Alves [this message]
2004-10-16  9:49 Unescape URL Procedure Andrew
2004-10-16 12:24 ` Pascal Obry
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox