Subject: Re: [boost] boost filesystem path as utf-8?
From: Beman Dawes (bdawes_at_[hidden])
Date: 2012-01-23 07:47:02
On Mon, Jan 23, 2012 at 4:46 AM, Yakov Galka <ybungalobill_at_[hidden]> wrote:
> As Artyom said you can imbue whatever locale you want to specify the
> conversion form narrow to wide strings. It will make almost all the
> conversions transparent, except that the path will still be stored as
> UTF-16 on windows.
So far, so good.
> Unfortunately it boils to the interface whence you can
> get a c_str() to a UTF-16 string only.
That's not correct.
If you have a path p, and the imbued codecvt if UTF-8, you can always
get a UTF-8 narrow string by writing p.string<std::string>(), so you
can always write p.string<std::string>().c_str() if you want a const
char* to a UTF-8 encoded narrow string.
If your app mostly needs UTF-8 strings, use std::string and only
convert to a path when a path is actually needed.
If your app mostly needs paths, use boost::filesystem::path and only
convert to std::string when a std::string or const char* is actually
> You may want to revert to Boost.Filesystem.v2 (afaik removed completely in
> 1.48 so you'll need to merge from the old release), it is better designed
> in the sense that it has a templatized basic_path that allows you to store
> utf-8 encoding internally (once you imbue the correct locale) and convert
> to UTF-16 on demand.
V2 is no longer supported and bugs are not being fixed.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk