mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 22:29:39 -06:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user