diff --git a/src/load_map.cpp b/src/load_map.cpp index b4f65bf11e..21234507b8 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -69,6 +69,10 @@ // stl #include +#ifdef _WINDOWS +#include +#endif + using boost::lexical_cast; using boost::bad_lexical_cast; using boost::tokenizer; @@ -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 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 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; @@ -695,7 +720,18 @@ void map_parser::parse_layer( Map & map, ptree const & lay ) std::string name = get_attr(param, "name"); std::string value = get_value( 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 != "" && paramIter->first != "" )