Why std::string is used for the file paths?

View: New views
8 Messages — Rating Filter:   Alert me  

Why std::string is used for the file paths?

by Roman R :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why std::string is used for the file paths?

Most of Miscellaneous Utility Functions (http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__MiscUtils.html),
Gio::File, Gtk::Image::set, Gdk::Pixbuf::create_from_file and so on.
Why not just use Glib:ustring everywhere?

For example, this simple code will cause a crash:
Gtk::Image image;
Glib::ustring path("image.png");
image.set(path);

Why I should write image.set(path.raw()); to prevent this crash?

Thanks.

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by milosz derezynski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Filesystems aren't in any particular encoding; there is no such thing as a "string class for file paths". On UNIX a file path is just a sequence of 8-bit characters, for which std::string is suited best, and for which Glib::ustring isn't needed. If any of the mentioned functions would take an Glib::ustring, the ustring would need to be passed to the relevant internal function using ::raw() anyway which would make any UTF-8ness it might or might not have there unneccessary.

2008/7/13 Roman Yazmin <roman.yazmin@...>:
Why std::string is used for the file paths?

Most of Miscellaneous Utility Functions (http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__MiscUtils.html),
Gio::File, Gtk::Image::set, Gdk::Pixbuf::create_from_file and so on.
Why not just use Glib:ustring everywhere?

For example, this simple code will cause a crash:
Gtk::Image image;
Glib::ustring path("image.png");
image.set(path);

Why I should write image.set(path.raw()); to prevent this crash?

Thanks.

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list




--
------------
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Roman R :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If library has own "string" class, and it is used,  it should be used everywhere.
No matter what happens internally. Library interface should be common.
Why we need this "string hell"?


On Sun, Jul 13, 2008 at 6:03 AM, Milosz Derezynski <internalerror@...> wrote:
Filesystems aren't in any particular encoding; there is no such thing as a "string class for file paths". On UNIX a file path is just a sequence of 8-bit characters, for which std::string is suited best, and for which Glib::ustring isn't needed. If any of the mentioned functions would take an Glib::ustring, the ustring would need to be passed to the relevant internal function using ::raw() anyway which would make any UTF-8ness it might or might not have there unneccessary.

2008/7/13 Roman Yazmin <roman.yazmin@...>:
Why std::string is used for the file paths?

Most of Miscellaneous Utility Functions (http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__MiscUtils.html),
Gio::File, Gtk::Image::set, Gdk::Pixbuf::create_from_file and so on.
Why not just use Glib:ustring everywhere?

For example, this simple code will cause a crash:
Gtk::Image image;
Glib::ustring path("image.png");
image.set(path);

Why I should write image.set(path.raw()); to prevent this crash?

Thanks.

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list




--
------------
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Toralf Lund :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Roman Yazmin wrote:
> If library has own "string" class, and it is used,  it should be used
> everywhere.
Gtkmm doesn't have its own "string" class. It has a special class for
UTF-8 encoded strings. That's what Glib::ustring is.

> No matter what happens internally. Library interface should be common.
> Why we need this "string hell"?
>
>
> On Sun, Jul 13, 2008 at 6:03 AM, Milosz Derezynski
> <internalerror@... <mailto:internalerror@...>> wrote:
>
>     Filesystems aren't in any particular encoding; there is no such
>     thing as a "string class for file paths". On UNIX a file path is
>     just a sequence of 8-bit characters, for which std::string is
>     suited best, and for which Glib::ustring isn't needed. If any of
>     the mentioned functions would take an Glib::ustring, the ustring
>     would need to be passed to the relevant internal function using
>     ::raw() anyway which would make any UTF-8ness it might or might
>     not have there unneccessary.
>
>     2008/7/13 Roman Yazmin <roman.yazmin@...
>     <mailto:roman.yazmin@...>>:
>
>         Why std::string is used for the file paths?
>
>         Most of Miscellaneous Utility Functions
>         (http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__MiscUtils.html),
>         Gio::File, Gtk::Image::set, Gdk::Pixbuf::create_from_file and
>         so on.
>         Why not just use Glib:ustring everywhere?
>
>         For example, this simple code will cause a crash:
>         Gtk::Image image;
>         Glib::ustring path("image.png");
>         image.set(path);
>
>         Why I should write image.set(path.raw()); to prevent this crash?
>
>         Thanks.
>
>         _______________________________________________
>         gtkmm-list mailing list
>         gtkmm-list@... <mailto:gtkmm-list@...>
>         http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>
>
>
>     --
>     ------------
>     Please note that according to the German law on data retention,
>     information on every electronic information exchange with me is
>     retained for a period of six months.
>     [Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung
>     zufolge
>     jeder elektronische Kontakt mit mir sechs Monate lang gespeichert
>     wird.]
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list@...
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>  


--
Toralf Lund <toralf@...> +47 66 85 51 22
ProCaptura AS                       +47 66 85 51 00 (switchboard)
http://www.procaptura.com/          +47 66 85 51 01 (fax)

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Roman R :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Gtkmm doesn't have its own "string" class. It has a special class for UTF-8 encoded strings. That's what Glib::ustring is.

And  all library use this special class for UTF-8 encoded strings. And must be used for file paths also.
If not, please show me the benefits of using std::string for file paths instead of ustring.

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Toralf Lund :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Roman Yazmin wrote:
>
>     Gtkmm doesn't have its own "string" class. It has a special class
>     for UTF-8 encoded strings. That's what Glib::ustring is.
>
>
> And  all library use this special class for UTF-8 encoded strings. And
> must be used for file paths also.
> If not, please show me the benefits of using std::string for file
> paths instead of ustring.
I think you are looking at this from the wrong side, so as to speak.

As far as I understand, Glib::ustring is not intended as a "separate"
string class. It may be implemented somewhat separately for some obscure
technical reason, but you should view it as a specialisation of
std::string with additional support for UTF-8 encoding and variable
length characters.

So, generally std::string is used all over the place. In some places, a
specialised class with support for a special case of a string, i.e. an
UTF-8 encoded text, is needed. This is where Glib::ustring is used. But
Glib::ustring "is a" std::string, at least conceptually. Other places,
strings are just general character sequences, so the generic string
class is used directly. std::string, that is.

Also using the current Glib::ustring implementation for the more general
strings may work from a technical perspective, but it would break with
the normal rules for object orientation, and Glib::ustring *might* also
be implemented in such a way that non-UTF-8 strings would simply be
rejected.

- Toralf

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Murray Cumming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2008-07-14 at 12:52 +0400, Roman Yazmin wrote:
>         Gtkmm doesn't have its own "string" class. It has a special
>         class for UTF-8 encoded strings. That's what Glib::ustring is.
>
> And  all library use this special class for UTF-8 encoded strings. And
> must be used for file paths also.
> If not, please show me the benefits of using std::string for file
> paths instead of ustring.

It makes it clear that you need to think about what encoding is used for
the filename, and does not offer you an API to manipulate non-UTF8
characters as UTF-8.

For instance, it makes it clear that you should probably use
filename_to_utf8() and filename_from_utf8() when showing the filepath to
a user or interpreting a filepath entered by a user.
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__CharsetConv.html#g2bd94064ad97b43324a7854b62f0835b

You really still need to be aware of these encodings on modern computer
system, unfortunately.

It also avoids an unwanted conversion when writing a filepath out to a C
++ standard stream, such as std::cout.

--
murrayc@...
www.murrayc.com
www.openismus.com

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Why std::string is used for the file paths?

by Roman R :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Much clear to use UTF8 (ustring) everywhere.
filename_to_utf8, filename_from_utf8(), etc should be hidden and should be used internally by library if neccessary.
Most modern operating systems use unicode for filenames/paths (UTF8 encoded or wide chars, doesn't matter).
By using ustring we simply remove the possibility of writing code that don't care about this.
The code written once will work on any system.

On Mon, Jul 14, 2008 at 1:33 PM, Murray Cumming <murrayc@...> wrote:
On Mon, 2008-07-14 at 12:52 +0400, Roman Yazmin wrote:
>         Gtkmm doesn't have its own "string" class. It has a special
>         class for UTF-8 encoded strings. That's what Glib::ustring is.
>
> And  all library use this special class for UTF-8 encoded strings. And
> must be used for file paths also.
> If not, please show me the benefits of using std::string for file
> paths instead of ustring.

It makes it clear that you need to think about what encoding is used for
the filename, and does not offer you an API to manipulate non-UTF8
characters as UTF-8.

For instance, it makes it clear that you should probably use
filename_to_utf8() and filename_from_utf8() when showing the filepath to
a user or interpreting a filepath entered by a user.
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/group__CharsetConv.html#g2bd94064ad97b43324a7854b62f0835b

You really still need to be aware of these encodings on modern computer
system, unfortunately.

It also avoids an unwanted conversion when writing a filepath out to a C
++ standard stream, such as std::cout.

--
murrayc@...
www.murrayc.com
www.openismus.com



_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list