summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar liamwhite2022-05-20 23:35:10 -0400
committerGravatar GitHub2022-05-20 23:35:10 -0400
commit4eb7f6c04473e3f90e2622ee00b822febe1ccef9 (patch)
treeb037dccee6a4b1a0b4228bef5d2af2f38526fb90
parentMerge pull request #8351 from abouvier/patch-2 (diff)
parentqt_software_keyboard: Address review feedback (diff)
downloadyuzu-4eb7f6c04473e3f90e2622ee00b822febe1ccef9.tar.gz
yuzu-4eb7f6c04473e3f90e2622ee00b822febe1ccef9.tar.xz
yuzu-4eb7f6c04473e3f90e2622ee00b822febe1ccef9.zip
Merge pull request #8342 from lat9nq/clang-latest-stdc++
general: Use Common::U16StringFromBuffer in place of QString::toStdU16String
-rw-r--r--src/common/string_util.cpp4
-rw-r--r--src/common/string_util.h2
-rw-r--r--src/yuzu/applets/qt_software_keyboard.cpp29
-rw-r--r--src/yuzu/main.cpp6
4 files changed, 25 insertions, 16 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 703aa5db8..7a495bc79 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -178,6 +178,10 @@ std::wstring UTF8ToUTF16W(const std::string& input) {
178 178
179#endif 179#endif
180 180
181std::u16string U16StringFromBuffer(const u16* input, std::size_t length) {
182 return std::u16string(reinterpret_cast<const char16_t*>(input), length);
183}
184
181std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) { 185std::string StringFromFixedZeroTerminatedBuffer(std::string_view buffer, std::size_t max_len) {
182 std::size_t len = 0; 186 std::size_t len = 0;
183 while (len < buffer.length() && len < max_len && buffer[len] != '\0') { 187 while (len < buffer.length() && len < max_len && buffer[len] != '\0') {
diff --git a/src/common/string_util.h b/src/common/string_util.h
index a33830aec..ce18a33cf 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -44,6 +44,8 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
44 44
45#endif 45#endif
46 46
47[[nodiscard]] std::u16string U16StringFromBuffer(const u16* input, std::size_t length);
48
47/** 49/**
48 * Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string 50 * Compares the string defined by the range [`begin`, `end`) to the null-terminated C-string
49 * `other` for equality. 51 * `other` for equality.
diff --git a/src/yuzu/applets/qt_software_keyboard.cpp b/src/yuzu/applets/qt_software_keyboard.cpp
index d3cf0b43b..e8b217d90 100644
--- a/src/yuzu/applets/qt_software_keyboard.cpp
+++ b/src/yuzu/applets/qt_software_keyboard.cpp
@@ -411,11 +411,11 @@ void QtSoftwareKeyboardDialog::ShowTextCheckDialog(
411 break; 411 break;
412 } 412 }
413 413
414 auto text = ui->topOSK->currentIndex() == 1 414 const auto text = ui->topOSK->currentIndex() == 1 ? ui->text_edit_osk->toPlainText()
415 ? ui->text_edit_osk->toPlainText().toStdU16String() 415 : ui->line_edit_osk->text();
416 : ui->line_edit_osk->text().toStdU16String(); 416 auto text_str = Common::U16StringFromBuffer(text.utf16(), text.size());
417 417
418 emit SubmitNormalText(SwkbdResult::Ok, std::move(text), true); 418 emit SubmitNormalText(SwkbdResult::Ok, std::move(text_str), true);
419 break; 419 break;
420 } 420 }
421 } 421 }
@@ -562,7 +562,7 @@ void QtSoftwareKeyboardDialog::keyPressEvent(QKeyEvent* event) {
562 return; 562 return;
563 } 563 }
564 564
565 InlineTextInsertString(entered_text.toStdU16String()); 565 InlineTextInsertString(Common::U16StringFromBuffer(entered_text.utf16(), entered_text.size()));
566} 566}
567 567
568void QtSoftwareKeyboardDialog::MoveAndResizeWindow(QPoint pos, QSize size) { 568void QtSoftwareKeyboardDialog::MoveAndResizeWindow(QPoint pos, QSize size) {
@@ -1119,11 +1119,11 @@ void QtSoftwareKeyboardDialog::NormalKeyboardButtonClicked(QPushButton* button)
1119 } 1119 }
1120 1120
1121 if (button == ui->button_ok || button == ui->button_ok_shift || button == ui->button_ok_num) { 1121 if (button == ui->button_ok || button == ui->button_ok_shift || button == ui->button_ok_num) {
1122 auto text = ui->topOSK->currentIndex() == 1 1122 const auto text = ui->topOSK->currentIndex() == 1 ? ui->text_edit_osk->toPlainText()
1123 ? ui->text_edit_osk->toPlainText().toStdU16String() 1123 : ui->line_edit_osk->text();
1124 : ui->line_edit_osk->text().toStdU16String(); 1124 auto text_str = Common::U16StringFromBuffer(text.utf16(), text.size());
1125 1125
1126 emit SubmitNormalText(SwkbdResult::Ok, std::move(text)); 1126 emit SubmitNormalText(SwkbdResult::Ok, std::move(text_str));
1127 return; 1127 return;
1128 } 1128 }
1129 1129
@@ -1189,7 +1189,8 @@ void QtSoftwareKeyboardDialog::InlineKeyboardButtonClicked(QPushButton* button)
1189 return; 1189 return;
1190 } 1190 }
1191 1191
1192 InlineTextInsertString(button->text().toStdU16String()); 1192 const auto button_text = button->text();
1193 InlineTextInsertString(Common::U16StringFromBuffer(button_text.utf16(), button_text.size()));
1193 1194
1194 // Revert the keyboard to lowercase if the shift key is active. 1195 // Revert the keyboard to lowercase if the shift key is active.
1195 if (bottom_osk_index == BottomOSKIndex::UpperCase && !caps_lock_enabled) { 1196 if (bottom_osk_index == BottomOSKIndex::UpperCase && !caps_lock_enabled) {
@@ -1282,11 +1283,11 @@ void QtSoftwareKeyboardDialog::TranslateButtonPress(Core::HID::NpadButton button
1282 if (is_inline) { 1283 if (is_inline) {
1283 emit SubmitInlineText(SwkbdReplyType::DecidedCancel, current_text, cursor_position); 1284 emit SubmitInlineText(SwkbdReplyType::DecidedCancel, current_text, cursor_position);
1284 } else { 1285 } else {
1285 auto text = ui->topOSK->currentIndex() == 1 1286 const auto text = ui->topOSK->currentIndex() == 1 ? ui->text_edit_osk->toPlainText()
1286 ? ui->text_edit_osk->toPlainText().toStdU16String() 1287 : ui->line_edit_osk->text();
1287 : ui->line_edit_osk->text().toStdU16String(); 1288 auto text_str = Common::U16StringFromBuffer(text.utf16(), text.size());
1288 1289
1289 emit SubmitNormalText(SwkbdResult::Cancel, std::move(text)); 1290 emit SubmitNormalText(SwkbdResult::Cancel, std::move(text_str));
1290 } 1291 }
1291 break; 1292 break;
1292 case Core::HID::NpadButton::Y: 1293 case Core::HID::NpadButton::Y:
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f607f464a..f4a9a7171 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1401,7 +1401,8 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
1401 if (loader != nullptr && loader->ReadProgramId(title_id) == Loader::ResultStatus::Success && 1401 if (loader != nullptr && loader->ReadProgramId(title_id) == Loader::ResultStatus::Success &&
1402 type == StartGameType::Normal) { 1402 type == StartGameType::Normal) {
1403 // Load per game settings 1403 // Load per game settings
1404 const auto file_path = std::filesystem::path{filename.toStdU16String()}; 1404 const auto file_path =
1405 std::filesystem::path{Common::U16StringFromBuffer(filename.utf16(), filename.size())};
1405 const auto config_file_name = title_id == 0 1406 const auto config_file_name = title_id == 0
1406 ? Common::FS::PathToUTF8String(file_path.filename()) 1407 ? Common::FS::PathToUTF8String(file_path.filename())
1407 : fmt::format("{:016X}", title_id); 1408 : fmt::format("{:016X}", title_id);
@@ -1482,7 +1483,8 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
1482 } 1483 }
1483 if (res != Loader::ResultStatus::Success || title_name.empty()) { 1484 if (res != Loader::ResultStatus::Success || title_name.empty()) {
1484 title_name = Common::FS::PathToUTF8String( 1485 title_name = Common::FS::PathToUTF8String(
1485 std::filesystem::path{filename.toStdU16String()}.filename()); 1486 std::filesystem::path{Common::U16StringFromBuffer(filename.utf16(), filename.size())}
1487 .filename());
1486 } 1488 }
1487 const bool is_64bit = system->Kernel().CurrentProcess()->Is64BitProcess(); 1489 const bool is_64bit = system->Kernel().CurrentProcess()->Is64BitProcess();
1488 const auto instruction_set_suffix = is_64bit ? tr("(64-bit)") : tr("(32-bit)"); 1490 const auto instruction_set_suffix = is_64bit ? tr("(64-bit)") : tr("(32-bit)");