2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-09-19 00:29:07 +00:00

Refactor QUtil::call_main_from_wmain

This commit is contained in:
m-holger 2024-05-16 23:10:28 +01:00
parent 7f8e0a0d22
commit 602d5eb61d

View File

@ -1899,7 +1899,8 @@ call_main_from_wmain(
// strings for compatibility with other systems. That way the rest of qpdf.cc can just act like
// arguments are UTF-8.
std::vector<std::unique_ptr<char[]>> utf8_argv;
std::vector<std::string> utf8_argv;
utf8_argv.reserve(QIntC::to_size(argc));
for (int i = 0; i < argc; ++i) {
std::string utf16;
for (size_t j = 0; j < std::wcslen(argv[i]); ++j) {
@ -1907,13 +1908,12 @@ call_main_from_wmain(
utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint >> 8)));
utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff)));
}
std::string utf8 = QUtil::utf16_to_utf8(utf16);
utf8_argv.push_back(QUtil::make_unique_cstr(utf8));
utf8_argv.emplace_back(QUtil::utf16_to_utf8(utf16));
}
auto utf8_argv_sp = std::make_unique<char*[]>(1 + utf8_argv.size());
char** new_argv = utf8_argv_sp.get();
for (size_t i = 0; i < utf8_argv.size(); ++i) {
new_argv[i] = utf8_argv.at(i).get();
new_argv[i] = utf8_argv.at(i).data();
}
argc = QIntC::to_int(utf8_argv.size());
new_argv[argc] = nullptr;