UICommon: Make use of fmt where applicable

Continues the migration to using fmt.

Notably, this allows safely converting a map within USBUtils over to
containing string view instances, rather than std::string instances, as
fmt safely handles the formatting of string views.
This commit is contained in:
Lioncash
2019-11-23 19:15:52 -05:00
parent ec895f544c
commit b28db1d4e6
7 changed files with 36 additions and 25 deletions

View File

@ -2,19 +2,22 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "UICommon/USBUtils.h"
#include <string_view>
#include <fmt/format.h>
#ifdef __LIBUSB__
#include <libusb.h>
#endif
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Core/LibusbUtils.h"
#include "UICommon/USBUtils.h"
// Because opening and getting the device name from devices is slow, especially on Windows
// with usbdk, we cannot do that for every single device. We should however still show
// device names for known Wii peripherals.
static const std::map<std::pair<u16, u16>, std::string> s_wii_peripherals = {{
static const std::map<std::pair<u16, u16>, std::string_view> s_wii_peripherals{{
{{0x046d, 0x0a03}, "Logitech Microphone"},
{{0x057e, 0x0308}, "Wii Speak"},
{{0x057e, 0x0309}, "Nintendo USB Microphone"},
@ -54,7 +57,7 @@ std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
std::string GetDeviceName(const std::pair<u16, u16> vid_pid)
{
const auto iter = s_wii_peripherals.find(vid_pid);
const std::string device_name = iter == s_wii_peripherals.cend() ? "Unknown" : iter->second;
return StringFromFormat("%04x:%04x - %s", vid_pid.first, vid_pid.second, device_name.c_str());
const std::string_view device_name = iter == s_wii_peripherals.cend() ? "Unknown" : iter->second;
return fmt::format("{:04x}:{:04x} - {}", vid_pid.first, vid_pid.second, device_name);
}
} // namespace USBUtils