Menu

#8 wchar_t filename support

Unstable (example)
open
nobody
wchar_t (1)
3
2014-02-28
2014-02-28
Tom Plunket
No

I wanted support for wchar_t for rapidxml::file filenames but the pre-existing patch didn't do it for me so I wrote another one. This "supports" other character types as well although it just strips all high bytes off of the characters.

It's "slower than necessary" for type char but we're erroring so that shouldn't be a problem.

    template <typename Fn>
    file(const Fn *filename)
    {
        using namespace std;

        // Open stream
        basic_ifstream<Ch> stream(filename, ios::binary);
        if (!stream.good())
        {
            // quick and dirty coersion from wchar_t if that's what Fn is.
            const Fn* fnend = filename;
            while (*fnend != 0)
                ++fnend;
            throw runtime_error(string("cannot open file ") + string(filename, fnend));
        }
        stream.unsetf(ios::skipws);
1 Attachments

Discussion


Log in to post a comment.