0

In a nutshell... in my app we use boost::filesystem::path a whole lot. It mostly works very well, EXCEPT if somebody decides to be cute and refer to a non-unicode filename in windows (say, for some reason I cannot fathom, somebody has a Shift-JIS filename).

As the say, ignorance is bliss and in mine, I thought I might be able to get around this by doing something along the lines of (Does this even make sense BTW?):

namespace fs = boost::filesystem;

class utf8Path : public fs::path {

    public:
    utf8Path () : fs::path () {};
    utf8Path (std::string path) : fs::path(UnicodeUtil::convertToUTF8(path)) {};
}

Of course, I wasn't taking into account all the various assignment and such operators.

Supposing what I wrote above makes sense and is not broken code... is it possible to extend this approach to other versions of the constructor, assignment operators and such?

nvoigt
  • 75,013
  • 26
  • 93
  • 142

1 Answers1

0

It is usually a bad design choice to inherit when composition is equally good or when you don't override any virtual methods. In the provided example, it hardly justifies a new class in the first place. Simply call the conversion in the places where it is needed instead of using the 'utf8path'.

Although im not familiar with this, there appears to be some support for codec_cvt.

darune
  • 10,480
  • 2
  • 24
  • 62
  • As I said above, `wpath` has been deprecated for quite a while, from which I assume it's not going to work any better than `path`. Now that you mention it, I do realize I could just make sure to sanitize the input to `filesystem::path` (which greatly reduces where I'll need to do it since it will only be places dealing with user input.) Still, for sake of argument... I'm not quite sure how might help me in here. Finally, even if it's a bad design choice, I'd like to know if my original attempt COULD work and whether what I was trying CAN be made to work with the rest of operators. – Gregorio Litenstein Sep 12 '18 at 13:16
  • It could work, yes. A custom Assignment operator will not be directly usuable in your class, but you will just have to figure a way to implement one for your class if thats the case, so in theory, yes, it will work fine. – darune Sep 12 '18 at 13:32