Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8514 from lioncash/sview
Common/Network: Make StringToMacAddress use a string_view
  • Loading branch information
JosJuice committed Dec 6, 2019
2 parents 15fc71c + 81edcca commit 5a5c46a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions Source/Core/Common/Network.cpp
Expand Up @@ -6,8 +6,6 @@

#include <algorithm>
#include <cctype>
#include <cstring>
#include <ctime>

#include <fmt/format.h>

Expand Down Expand Up @@ -43,10 +41,10 @@ std::string MacAddressToString(const MACAddress& mac)
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())
return {};
return std::nullopt;

int x = 0;
MACAddress mac{};
Expand All @@ -70,7 +68,7 @@ std::optional<MACAddress> StringToMacAddress(const std::string& mac_string)
// nibble is a character in the MAC address, making 12 characters
// in total.
if (x / 2 != MAC_ADDRESS_SIZE)
return {};
return std::nullopt;

return std::make_optional(mac);
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Common/Network.h
Expand Up @@ -7,6 +7,7 @@
#include <array>
#include <optional>
#include <string>
#include <string_view>

#include "Common/CommonTypes.h"

Expand All @@ -27,5 +28,5 @@ using MACAddress = std::array<u8, MAC_ADDRESS_SIZE>;

MACAddress GenerateMacAddress(MACConsumer type);
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

0 comments on commit 5a5c46a

Please sign in to comment.