MCPcopy Create free account
hub / github.com/colmap/colmap / CodePageToUTF8Win

Function CodePageToUTF8Win

src/colmap/util/string.cc:139–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137#ifdef _WIN32
138
139std::string CodePageToUTF8Win(const std::string& str, unsigned int code_page) {
140 int wide_len = MultiByteToWideChar(code_page, 0, str.c_str(), -1, nullptr, 0);
141 if (wide_len <= 0) return "";
142
143 std::wstring wide_str(wide_len, L'\0');
144 MultiByteToWideChar(code_page, 0, str.c_str(), -1, &wide_str[0], wide_len);
145
146 int utf8_len = WideCharToMultiByte(
147 CP_UTF8, 0, wide_str.c_str(), -1, nullptr, 0, nullptr, nullptr);
148 if (utf8_len <= 0) return "";
149
150 std::string utf8_str(utf8_len, '\0');
151 WideCharToMultiByte(CP_UTF8,
152 0,
153 wide_str.c_str(),
154 -1,
155 &utf8_str[0],
156 utf8_len,
157 nullptr,
158 nullptr);
159
160 if (!utf8_str.empty() && utf8_str.back() == '\0') {
161 utf8_str.pop_back();
162 }
163
164 return utf8_str;
165};
166
167std::string UTF8ToCodePageWin(const std::string& str, unsigned int code_page) {
168 int wide_len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);

Callers 2

TESTFunction · 0.85
PlatformToUTF8Function · 0.85

Calls 1

emptyMethod · 0.80

Tested by 1

TESTFunction · 0.68