Re: Can someone please comment on this short program

On Wed, 2005-12-14 at 16:05 +0100, Murray Cumming wrote:
> > Alexander Larsson wrote:
> >> I'm not sure where the confusion is. I can't talk for the c++ bindings,
> >> but for gnome-vfs itself the rule is:
> >>
> >>   * file: URIs have no inherent encoding
> >>
> >> None, nada, zilch. They are the filename as stored on disk, escaped into
> >> a uri. As such, they are essentially escaped byte strings, the only
> >> limit being that zero bytes and '/' bytes are not allowed. This is a
> >> direct result of the fact that unix filenames have no encoding, and is
> >> nothing we can anything do about in gnome-vfs.
> >
> > Yes, I actually think the problem lies in the C++ bindings, because as
> > opposed to gnome_vfs_uri_new(), the construction of a Gnome::Vfs::Uri in
> > gnome-vfsmm requires the string which is passed to Uri::create() to be
> > encoded in UTF-8
> I probably heard somewhere that all URIs are UTF-8 encoded. I didn't take
> the time to look at the appropriate W3C specification, RFC, etc. I also
> assumed that URIs are escaped.

This is partially correct. All URIs are (after escaping) ASCII encoded,
thus also UTF-8. However, there is no rule that i know of specifying the
encoding of an unescaped uri.

> In your test case, you are using the C++ wrapper for
> gnome_vfs_get_uri_from_local_path(filepath).
> I wonder what this does? Does it just add file:// at the start without
> doing any escaping/encoding-conversoin?

No, it fully escapes the passed in filename (i.e. basically a byte
array) so that its a valid URI.

> > (that's because create() takes a Glib::ustring, and if
> > you pass an std::string in place of a Glib::ustring--such as the one
> > returned from FileInfo::get_name()--a conversion attempt will be made).
> I don't think that's true, but maybe I'm looking at the wrong part of the
> Glib::ustring string source. The ustring(std::string) constructor does a
> simple assignment.

Independent on the C++ conversions involved, this should not be a
problem for a very simple reason. All URIs are valid ascii strings, and
as such convert losslessy to/from UTF8.

I'm not sure why there is a reference to FileInfo::get_name() and create
here though. get_name gives a filename (i.e. it is not uri-escaped),
whereas create takes a uri argument. If you want to use the name given
by get_name to construct a uri you typically use
gnome_vfs_uri_append_file_name() on the base uri and the filename,
giving you a properly uri-escaped ascii string.

 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's an obese moralistic librarian gone bad. She's a high-kicking mute vampire 
with the soul of a mighty warrior. They fight crime! 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]