From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Open URLs
Date: Sun, 3 Jan 2010 21:05:46 +0100
Date: 2010-01-03T21:05:47+01:00 [thread overview]
Message-ID: <1exooomj74fsx.1k5y7r1avujek$.dlg@40tude.net> (raw)
In-Reply-To: dfd5fbb5-a8c0-49e0-9a0b-4fb038089da8@34g2000yqp.googlegroups.com
On Sun, 3 Jan 2010 10:17:58 -0800 (PST), vlc wrote:
> I am looking for a way to open URLs (like "file:///home/vlc/file") as
> files - as you would do with "Open (Handle, In_File, "/home/vlc/
> file")".
>
> I could surely just remove the heading "file://", but this would still
> leave me with the problem of special characters like "file:///home/vlc/
> name%20with%20spaces".
The third / is a delimiter, theoretically there could be something between
file:// and /. The path might be followed by queries and fragments, see
here:
http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
> Does anybody know of a way to translate URLs to paths?
You just parse it. What is the problem, except that the number of URI
schemes is huge.
Regarding replacing %20 with SP, I am not sure if this has to be done. You
have to dig the documents (RFC) to verify if %<number> is indeed a defined
escape sequence, if there are any in the URI, I do not remember. Otherwise
it is a part of the file name to be passed further as is.
In any case, when you write a parser, you could make it recognize escape
sequences, delimiters etc as it moves the cursor left to right. Something
like:
Pointer := URI'First;
... -- Get scheme, advance pointer
case Scheme is
when File_Schema =>
declare
Path : Unbounded_String;
Code_Point : Integer;
begin
loop
if URI (Pointer) = '%' then
Get (URI, Pointer, Code_Point);
Append (Path, Character'Val (Code_Point));
elsif Is_In (Delimiters, URI (Pointer)) then
exit;
else
Append (Path, URI (Pointer));
Pointer := Pointer + 1;
end if;
exit when Pointer > URI'Last;
end loop;
...
etc
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2010-01-03 20:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-03 18:17 Open URLs vlc
2010-01-03 18:36 ` Gautier write-only
2010-01-03 18:36 ` Pascal Obry
2010-01-03 18:53 ` vlc
2010-01-03 20:05 ` Dmitry A. Kazakov [this message]
2010-01-14 8:32 ` David Thompson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox