MCPcopy Create free account
hub / github.com/OSGeo/PROJ / Win32Recode

Function Win32Recode

src/filemanager.cpp:559–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

557// ---------------------------------------------------------------------------
558
559static std::string Win32Recode(const char *src, unsigned src_code_page,
560 unsigned dst_code_page) {
561 // Convert from source code page to Unicode.
562
563 // Compute the length in wide characters.
564 int wlen = MultiByteToWideChar(src_code_page, MB_ERR_INVALID_CHARS, src, -1,
565 nullptr, 0);
566 if (wlen == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
567 return std::string();
568 }
569
570 // Do the actual conversion.
571 std::wstring wbuf;
572 wbuf.resize(wlen);
573 MultiByteToWideChar(src_code_page, 0, src, -1, &wbuf[0], wlen);
574
575 // Convert from Unicode to destination code page.
576
577 // Compute the length in chars.
578 int len = WideCharToMultiByte(dst_code_page, 0, &wbuf[0], -1, nullptr, 0,
579 nullptr, nullptr);
580
581 // Do the actual conversion.
582 std::string out;
583 out.resize(len);
584 WideCharToMultiByte(dst_code_page, 0, &wbuf[0], -1, &out[0], len, nullptr,
585 nullptr);
586 out.resize(strlen(out.c_str()));
587
588 return out;
589}
590
591#endif // _defined(_WIN32)
592

Callers 2

getProjDataEnvVarMethod · 0.85
pj_open_lib_internalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected