MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / ansiToOEM

Function ansiToOEM

cli/cppcheckexecutor.cpp:570–586  ·  view source on GitHub ↗

fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'

Source from the content-addressed store, hash-verified

568#ifdef _WIN32
569// fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'
570static 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)

Callers 2

reportErrMethod · 0.85
reportOutMethod · 0.85

Calls 1

dataMethod · 0.45

Tested by

no test coverage detected