Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2022-08-15 20:57:26


On 8/15/22 22:35, Peter Dimov via Boost wrote:
> Vinnie Falco wrote:
>> On Mon, Aug 15, 2022 at 11:28 AM Peter Dimov via Boost
>> <boost_at_[hidden]> wrote:
>>> That's why I think that the only sensible interpretation of paths
>>> coming from URLs is as UTF-8, and for this case, the default
>>> filesystem conversion isn't suitable.
>>
>> Can you please submit a pull request showing me how route.cpp can be
>> correctly implemented according to these semantics?
>
> The usual approach is to put
>
> boost::filesystem::path::imbue( std::locale( std::locale::classic(),
> new boost::filesystem::detail::utf8_codecvt_facet ) );

I'd rather

  boost::filesystem::path::imbue(boost::locale::generator()("C.UTF-8"));

Don't recommend users to use stuff from namespace detail. :)

Note though that after that call all narrow strings you pass to
filesystem::path must be UTF-8; you should be careful if you obtain
paths from user input, files, network, etc.

> as the first thing in `main`.
>
> fs::path has overloads taking codecvt_type, but I've never used them
> so I don't know how they work. Maybe Andrey can help.

If you made call above then that is the only thing you need to do. The
overloads taking codecvt is for when you don't want to set the global
filesystem locale for some reason. This may be useful during global
destructors stage, for example. By default, the codecvt is taken from
the global filesystem locale.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk