2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-02 22:50:20 +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 // strings for compatibility with other systems. That way the rest of qpdf.cc can just act like
// arguments are UTF-8. // 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) { for (int i = 0; i < argc; ++i) {
std::string utf16; std::string utf16;
for (size_t j = 0; j < std::wcslen(argv[i]); ++j) { 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 >> 8)));
utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff))); utf16.append(1, static_cast<char>(QIntC::to_uchar(codepoint & 0xff)));
} }
std::string utf8 = QUtil::utf16_to_utf8(utf16); utf8_argv.emplace_back(QUtil::utf16_to_utf8(utf16));
utf8_argv.push_back(QUtil::make_unique_cstr(utf8));
} }
auto utf8_argv_sp = std::make_unique<char*[]>(1 + utf8_argv.size()); auto utf8_argv_sp = std::make_unique<char*[]>(1 + utf8_argv.size());
char** new_argv = utf8_argv_sp.get(); char** new_argv = utf8_argv_sp.get();
for (size_t i = 0; i < utf8_argv.size(); ++i) { 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()); argc = QIntC::to_int(utf8_argv.size());
new_argv[argc] = nullptr; new_argv[argc] = nullptr;