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

Function UTF8ToCodePageWin

src/colmap/util/string.cc:167–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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);
169 if (wide_len <= 0) return "";
170
171 std::wstring wide_str(wide_len, L'\0');
172 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &wide_str[0], wide_len);
173
174 int local_len = WideCharToMultiByte(
175 code_page, 0, wide_str.c_str(), -1, nullptr, 0, nullptr, nullptr);
176 if (local_len <= 0) return "";
177
178 std::string local_str(local_len, '\0');
179 WideCharToMultiByte(code_page,
180 0,
181 wide_str.c_str(),
182 -1,
183 &local_str[0],
184 local_len,
185 nullptr,
186 nullptr);
187
188 if (!local_str.empty() && local_str.back() == '\0') {
189 local_str.pop_back();
190 }
191
192 return local_str;
193}
194
195#endif
196

Callers 2

TESTFunction · 0.85
UTF8ToPlatformFunction · 0.85

Calls 1

emptyMethod · 0.80

Tested by 1

TESTFunction · 0.68