Address remaining review comments

This commit is contained in:
fearlessTobi 2019-04-07 15:58:42 +02:00
parent 1517d2fef7
commit e9bd34f7da
4 changed files with 35 additions and 10 deletions

View file

@ -41,7 +41,7 @@ public:
Path(const char* path) : type(LowPathType::Char), string(path) {}
Path(std::vector<u8> binary_data) : type(LowPathType::Binary), binary(std::move(binary_data)) {}
template <std::size_t size>
Path(std::array<u8, size> binary_data)
Path(const std::array<u8, size>& binary_data)
: type(LowPathType::Binary), binary(binary_data.begin(), binary_data.end()) {}
Path(LowPathType type, const std::vector<u8>& data);

View file

@ -18,7 +18,7 @@ constexpr char MII_BUTTON_CANCEL[] = "Cancel";
/// later learn is needed can be added here and filled in by the backend HLE applet
struct MiiSelectorConfig {
bool enable_cancel_button;
std::u16string title;
std::string title;
u32 initially_selected_mii_index;
};

View file

@ -19,6 +19,20 @@
namespace HLE::Applets {
/**
* Converts a UTF-16 text in a container to a UTF-8 std::string.
*/
template <typename T>
std::string TextFromBuffer(const T& text) {
const auto text_end = std::find(text.begin(), text.end(), u'\0');
const std::size_t text_size = std::distance(text.begin(), text_end);
std::u16string buffer(text_size, 0);
std::transform(text.begin(), text_end, buffer.begin(), [](u16_le character) {
return static_cast<char16_t>(static_cast<u16>(character));
});
return Common::UTF16ToUTF8(buffer);
}
ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) {
if (parameter.signal != Service::APT::SignalType::Request) {
LOG_ERROR(Service_APT, "unsupported signal {}", static_cast<u32>(parameter.signal));
@ -142,10 +156,7 @@ MiiResult MiiSelector::GetStandardMiiResult() {
Frontend::MiiSelectorConfig MiiSelector::ToFrontendConfig(const MiiConfig& config) const {
Frontend::MiiSelectorConfig frontend_config;
frontend_config.enable_cancel_button = config.enable_cancel_button == 1;
std::transform(config.title.begin(), config.title.end(),
std::back_inserter(frontend_config.title), [](u16_le character) -> char16_t {
return static_cast<char16_t>(static_cast<u16>(character));
});
frontend_config.title = TextFromBuffer(config.title);
frontend_config.initially_selected_mii_index = config.initially_selected_mii_index;
return frontend_config;
}