MCPcopy Create free account
hub / github.com/Kitware/VTK / Win32Recode

Function Win32Recode

ThirdParty/libproj/vtklibproj/src/filemanager.cpp:547–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

545// ---------------------------------------------------------------------------
546
547static std::string Win32Recode(const char *src, unsigned src_code_page,
548 unsigned dst_code_page) {
549 // Convert from source code page to Unicode.
550
551 // Compute the length in wide characters.
552 int wlen = MultiByteToWideChar(src_code_page, MB_ERR_INVALID_CHARS, src, -1,
553 nullptr, 0);
554 if (wlen == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
555 return std::string();
556 }
557
558 // Do the actual conversion.
559 std::wstring wbuf;
560 wbuf.resize(wlen);
561 MultiByteToWideChar(src_code_page, 0, src, -1, &wbuf[0], wlen);
562
563 // Convert from Unicode to destination code page.
564
565 // Compute the length in chars.
566 int len = WideCharToMultiByte(dst_code_page, 0, &wbuf[0], -1, nullptr, 0,
567 nullptr, nullptr);
568
569 // Do the actual conversion.
570 std::string out;
571 out.resize(len);
572 WideCharToMultiByte(dst_code_page, 0, &wbuf[0], -1, &out[0], len, nullptr,
573 nullptr);
574 out.resize(strlen(out.c_str()));
575
576 return out;
577}
578
579// ---------------------------------------------------------------------------
580

Callers 2

getProjLibEnvVarMethod · 0.85
pj_open_lib_internalFunction · 0.85

Calls 3

stringClass · 0.50
resizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected