Menu

#1 rapidxml::file wchar_t filename support

open
nobody
None
5
2014-02-28
2010-02-17
drsurgeon
No

At the moment only char* filenames can be specified with rapidxml::file. However, it would be even more useful if it supported wchar_t* filenames.

As one possible solution, I have experimented with making the filename type a template parameter, as follows:

rapidxml::file<char,wchar_t> xml_file(L"asdf.xml");

template<class Ch = char, class Fnt = char>
class file
{
public:

//! Loads file into the memory. Data will be automatically destroyed by the destructor.
//! \param filename Filename to load.
file(const Fnt *filename)
{
using namespace std;
// Open stream
basic_ifstream<Ch> stream(filename, ios::binary);
if (!stream)
throw runtime_error(string("cannot open file "));

The code snippet above works with wchar_t, but had to modify the throw runtime_error to not append the filename.

Obviously there are many other ways to implement wchar_t filename support.

Thank you.

Discussion

  • drsurgeon

    drsurgeon - 2010-02-17
    • summary: rapidxml::file wchar_t support --> rapidxml::file wchar_t filename support
     
  • drsurgeon

    drsurgeon - 2010-02-23

    wchar_t filename support

     
  • Tom Plunket

    Tom Plunket - 2014-02-28

    See https://sourceforge.net/p/rapidxml/patches/8/ for a version which avoids adding another template parameter to the class (it adds one to the constructor only) and also writes the filename as the char version did to the exception that is thrown.

     

Log in to post a comment.