mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Merge pull request #8514 from lioncash/sview
Common/Network: Make StringToMacAddress use a string_view
This commit is contained in:
commit
5a5c46a8b1
@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <cstring>
|
|
||||||
#include <ctime>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
@ -43,10 +41,10 @@ std::string MacAddressToString(const MACAddress& mac)
|
|||||||
mac[4], mac[5]);
|
mac[4], mac[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<MACAddress> StringToMacAddress(const std::string& mac_string)
|
std::optional<MACAddress> StringToMacAddress(std::string_view mac_string)
|
||||||
{
|
{
|
||||||
if (mac_string.empty())
|
if (mac_string.empty())
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
|
||||||
int x = 0;
|
int x = 0;
|
||||||
MACAddress mac{};
|
MACAddress mac{};
|
||||||
@ -70,7 +68,7 @@ std::optional<MACAddress> StringToMacAddress(const std::string& mac_string)
|
|||||||
// nibble is a character in the MAC address, making 12 characters
|
// nibble is a character in the MAC address, making 12 characters
|
||||||
// in total.
|
// in total.
|
||||||
if (x / 2 != MAC_ADDRESS_SIZE)
|
if (x / 2 != MAC_ADDRESS_SIZE)
|
||||||
return {};
|
return std::nullopt;
|
||||||
|
|
||||||
return std::make_optional(mac);
|
return std::make_optional(mac);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
|
||||||
@ -27,5 +28,5 @@ using MACAddress = std::array<u8, MAC_ADDRESS_SIZE>;
|
|||||||
|
|
||||||
MACAddress GenerateMacAddress(MACConsumer type);
|
MACAddress GenerateMacAddress(MACConsumer type);
|
||||||
std::string MacAddressToString(const MACAddress& mac);
|
std::string MacAddressToString(const MACAddress& mac);
|
||||||
std::optional<MACAddress> StringToMacAddress(const std::string& mac_string);
|
std::optional<MACAddress> StringToMacAddress(std::string_view mac_string);
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
Loading…
Reference in New Issue
Block a user