Jon Cruz <jon@...360...> writes:
The only surprise you need to be aware of, if your string bits are
stored as
utf8 rather than the native narrow type, is that you need to use:
filesystem::detail::utf8_codecvt_facet utf8; path(myUtf8String, utf);
We do hit another issue.
On Windows, there is no safe narrow string encoding for paths. If one uses
only ASCII characters to name
files and folders, things might appear to work. However, as soon as you
encounter something not in the
current Windows ANSI Code Page, that falls apart.
Yes, it's not a problem internally, since internally boost::path and std::path use whatever data type is most appropriate to the platform, but unfortunately C++ doesn't have a decent way to differentiate between narrow strings and utf8 strings, so you need to know what kind of string you're holding when you construct the path.
In my work, and I suspect yours, most strings are utf8, so you need to use the workarounds I posted when making paths out of strings.*
You'll notice the std::tr2 version is more concise, since they made a u8path factory, which is quite nice. They also added a u8string() method, which is also a nice addition, although in my work I don't often find myself turning paths into strings; most often it's the other way around.
Since you're wary of adding a new runtime dependency, it's probably best just to wait for std::tr2::filesystem to make its way into std:: before migrating. It might take a couple of years before std::filesystem is reliably included with most compilers, but in the grand timeline of Inkscape, that's not all that long.
-Rick-
* Technically, you could stick to std::u16string, which is assumed to be UTF-encoded, but personally I prefer to stick to utf8.