Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-16 17:45:29


Recently, I needed to fix a program to work properly with paths that cannot
be represented by narrow strings under Windows. The problematic filenames
came from the user via drag and drop. I tried to go the wstring route, the
same approach that the filesystem library takes; but it was harder than I
thought. Many parts of the code base assumed narrow paths.

At the end I reverted the changes and just encoded the wide path into UTF-8
at the very start, passed the UTF-8 string through the existing code, then
decoded the UTF-8 into a wstring at the very end, immediately before calling
the Windows API. It worked.

What this means in the [filesystem] context? Basically, instead of:

template<class String, class Traits> class basic_path;

I used something similar to:

class path
{
private:

    string data_; // UTF-8, exposition only

public:

    path( wstring const & s );
    path( string const & s, encoding_type encoding = system_default );

    wstring to_wstring() const;
    string to_string( encoding_type encoding = system_default ) const;
};

--
Peter Dimov
http://www.pdimov.com 

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