fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'
| 568 | #ifdef _WIN32 |
| 569 | // fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII' |
| 570 | static inline std::string ansiToOEM(const std::string &msg, bool doConvert) |
| 571 | { |
| 572 | if (doConvert) { |
| 573 | const unsigned msglength = msg.length(); |
| 574 | // convert ANSI strings to OEM strings in two steps |
| 575 | std::vector<WCHAR> wcContainer(msglength); |
| 576 | std::string result(msglength, '\0'); |
| 577 | |
| 578 | // ansi code page characters to wide characters |
| 579 | MultiByteToWideChar(CP_ACP, 0, msg.data(), msglength, wcContainer.data(), msglength); |
| 580 | // wide characters to oem codepage characters |
| 581 | WideCharToMultiByte(CP_OEMCP, 0, wcContainer.data(), msglength, &result[0], msglength, nullptr, nullptr); |
| 582 | |
| 583 | return result; // hope for return value optimization |
| 584 | } |
| 585 | return msg; |
| 586 | } |
| 587 | #else |
| 588 | // no performance regression on non-windows systems |
| 589 | #define ansiToOEM(msg, doConvert) (msg) |