Skip to content

Commit

Permalink
Allow the file path of datasource contains no-ascii characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
avlee committed Feb 8, 2012
1 parent 16828ec commit fe652b2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/load_map.cpp
Expand Up @@ -69,6 +69,10 @@
// stl
#include <iostream>

#ifdef _WINDOWS
#include <Windows.h>
#endif

using boost::lexical_cast;
using boost::bad_lexical_cast;
using boost::tokenizer;
Expand Down Expand Up @@ -132,6 +136,27 @@ class map_parser : boost::noncopyable {

};

#ifdef _WINDOWS
std::string wstring2string(const std::wstring& s)
{
int slength = (int)s.length() + 1;
int len = ::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
boost::scoped_array<char> buf_ptr(new char [len+1]);
::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, buf_ptr.get(), len, 0, 0);
std::string r(buf_ptr.get());
return r;
}

std::wstring utf8ToWide( const std::string& str )
{
int len = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
boost::scoped_array<wchar_t> buf_ptr(new wchar_t [len+1]);
::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, buf_ptr.get(), len);
std::wstring rt(buf_ptr.get());
return rt;
}
#endif

void load_map(Map & map, std::string const& filename, bool strict)
{
ptree pt;
Expand Down Expand Up @@ -695,7 +720,18 @@ void map_parser::parse_layer( Map & map, ptree const & lay )
std::string name = get_attr<std::string>(param, "name");
std::string value = get_value<std::string>( param,
"datasource parameter");
#ifdef _WINDOWS
if (name == "file")
{
params[name] = wstring2string(utf8ToWide(value));
}
else
{
params[name] = value;
}
#else
params[name] = value;
#endif
}
else if( paramIter->first != "<xmlattr>" &&
paramIter->first != "<xmlcomment>" )
Expand Down

0 comments on commit fe652b2

Please sign in to comment.