|
Boost : |
Subject: Re: [boost] boost filesystem path as utf-8?
From: Beman Dawes (bdawes_at_[hidden])
Date: 2012-01-23 18:41:32
On Mon, Jan 23, 2012 at 5:15 PM, Emil Dotchevski
<emildotchevski_at_[hidden]> wrote:
>
>
> How exactly do I imbue UTF-8 codecvt in a path? I Googled around and
> couldn't find anything.
There are two approaches:
* If you always want all class path arguments and returned values with
a value type of char to be treated as being UTF-8 encoded, and aren't
worried about changing a potentially dangerous global, then do this:
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
...
std::locale global_loc = std::locale();
std::locale loc(global_loc, new
boost::filesystem::detail::utf8_codecvt_facet);
boost::filesystem::path::imbue(loc);
* If you only want one specific path to treat its narrow character
arguments and returns as UTF-8, do this:
boost::filesystem::detail::utf8_codecvt_facet utf8;
...
boost::filesystem::path p;
...
p.assign(u8"...", utf8); // many other path functions can take a
codecvt argument, too
By the way, you can use a UTF-8 codecvt facet from someone else if you prefer.
HTH,
--Beman
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk