From 25be09c7a3c7962e04a0eabdfe94c9359c6b87b3 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Mon, 18 Mar 2019 22:02:31 +0800 Subject: [PATCH] applets/swkbd: Address comments --- src/core/frontend/applets/swkbd.cpp | 2 +- src/core/frontend/applets/swkbd.h | 2 +- src/core/hle/applets/swkbd.cpp | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/core/frontend/applets/swkbd.cpp b/src/core/frontend/applets/swkbd.cpp index 12788d945..d4368bcc6 100644 --- a/src/core/frontend/applets/swkbd.cpp +++ b/src/core/frontend/applets/swkbd.cpp @@ -132,7 +132,7 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) { return ValidationError::None; } -bool SoftwareKeyboard::DataReady() { +bool SoftwareKeyboard::DataReady() const { return data_ready; } diff --git a/src/core/frontend/applets/swkbd.h b/src/core/frontend/applets/swkbd.h index c08dbe1d1..1e803411f 100644 --- a/src/core/frontend/applets/swkbd.h +++ b/src/core/frontend/applets/swkbd.h @@ -93,7 +93,7 @@ public: /** * Whether the result data is ready to be received. */ - bool DataReady(); + bool DataReady() const; /** * Receives the current result data stored in the applet, and clears the ready state. diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index 8e3b916e1..da4d0bf0a 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -26,12 +26,12 @@ namespace HLE::Applets { */ template inline std::string TextFromBuffer(const T& text) { - std::size_t text_size = text.size(); const auto text_end = std::find(text.begin(), text.end(), u'\0'); - if (text_end != text.end()) - text_size = std::distance(text.begin(), text_end); + const std::size_t text_size = std::distance(text.begin(), text_end); std::u16string buffer(text_size, 0); - std::memcpy(buffer.data(), text.data(), text_size * sizeof(u16)); + std::transform(text.begin(), text_end, buffer.begin(), [](u16_le character) { + return static_cast(static_cast(character)); + }); return Common::UTF16ToUTF8(buffer); } @@ -44,7 +44,7 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con Service::APT::CaptureBufferInfo capture_info; ASSERT(sizeof(capture_info) == parameter.buffer.size()); - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); + std::memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); using Kernel::MemoryPermission; // Create a SharedMemory that directly points to this heap block. @@ -69,7 +69,7 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter con ASSERT_MSG(parameter.buffer.size() == sizeof(config), "The size of the parameter (SoftwareKeyboardConfig) is wrong"); - memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); + std::memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); switch (config.callback_result) { case SoftwareKeyboardCallbackResult::OK: @@ -177,8 +177,6 @@ void SoftwareKeyboard::Update() { message.sender_id = id; SendParameter(message); } else { - // TODO(Subv): We're finalizing the applet immediately after it's started, - // but we should defer this call until after all the input has been collected. Finalize(); } }