| | 29 | #if defined(WIN32) && !defined(__CYGWIN__) |
| | 30 | #define WIN32_LEAN_AND_MEAN |
| | 31 | //For MultiByteToWideChar |
| | 32 | #include <Windows.h> |
| | 33 | #endif |
| | 34 | |
| | 35 | // This function belongs in osgDB. Delete this function and use the osgDB |
| | 36 | // version once Robert accepts the submission. |
| | 37 | std::string convertStringFromCurrentCodePageToUTF8(const std::string& str) |
| | 38 | { |
| | 39 | #if defined(WIN32) && !defined(__CYGWIN__) |
| | 40 | if (str.length() == 0) |
| | 41 | { |
| | 42 | return std::string(); |
| | 43 | } |
| | 44 | |
| | 45 | int utf16Length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), 0, 0); |
| | 46 | if (utf16Length <= 0) |
| | 47 | { |
| | 48 | osg::notify(osg::WARN) << "Cannot convert multi-byte string to UTF-8." << std::endl; |
| | 49 | return std::string(); |
| | 50 | } |
| | 51 | |
| | 52 | std::wstring sUTF16(utf16Length, L'\0'); |
| | 53 | utf16Length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), &sUTF16[0], utf16Length); |
| | 54 | if (utf16Length <= 0) |
| | 55 | { |
| | 56 | osg::notify(osg::WARN) << "Cannot convert multi-byte string to UTF-8." << std::endl; |
| | 57 | return std::string(); |
| | 58 | } |
| | 59 | |
| | 60 | return osgDB::convertUTF16toUTF8(sUTF16); |
| | 61 | #else |
| | 62 | return str; |
| | 63 | #endif |
| | 64 | } |