9#include "../microfmt.hpp"
23 T, std::void_t<decltype(std::declval<const T &>().data()), decltype(std::declval<const T &>().size())>>
24 : std::integral_constant<bool, std::is_convertible_v<decltype(std::declval<const T &>().data()), const uint8_t *> &&
25 std::is_convertible_v<decltype(std::declval<const T &>().size()), size_t>> {};
36 bool uppercase{
false};
44[[nodiscard]]
constexpr mac_view mac(span<const uint8_t>
bytes,
char separator =
':',
bool uppercase =
false) noexcept {
49[[nodiscard]]
constexpr mac_view mac(
const uint8_t (&arr)[6],
char separator =
':',
bool uppercase =
false) noexcept {
50 return mac_view{span<const uint8_t>(arr, 6), separator, uppercase};
54[[nodiscard]]
constexpr mac_view mac(
const uint8_t (&arr)[8],
char separator =
':',
bool uppercase =
false) noexcept {
55 return mac_view{span<const uint8_t>(arr, 8), separator, uppercase};
59template <typename ContainerT, std::enable_if_t<detail::is_mac_container<ContainerT>::value,
int> = 0>
60[[nodiscard]]
constexpr mac_view mac(
const ContainerT &c,
char separator =
':',
bool uppercase =
false) noexcept {
61 return mac_view{span<const uint8_t>(c.data(), c.size()), separator, uppercase};
64template <
typename ContainerT,
65 std::enable_if_t<!std::is_lvalue_reference_v<ContainerT> &&
66 detail::is_mac_container<std::remove_reference_t<ContainerT>>::value,
68[[nodiscard]]
constexpr mac_view mac(ContainerT &&,
char =
':',
bool =
false) noexcept = delete;
75 char parse_separator{
'\0'};
76 bool parse_uppercase{
false};
77 bool parse_case_set{
false};
80 for (
char c : ctx.spec()) {
82 parse_uppercase =
true;
83 parse_case_set =
true;
84 }
else if (c ==
'x') {
85 parse_uppercase =
false;
86 parse_case_set =
true;
87 }
else if (c ==
'-' || c ==
':' || c ==
'.' || c ==
'_') {
94 const size_t len = mv.bytes.size();
95 if (len != 6 && len != 8) {
96 out.write(
"00:00:00:00:00:00");
100 const char sep = (parse_separator !=
'\0') ? parse_separator : mv.separator;
101 const bool is_upper = parse_case_set ? parse_uppercase : mv.uppercase;
102 const auto &hex_digits = is_upper ? detail::hex_digits_upper : detail::hex_digits_lower;
104 for (
size_t i = 0; i < len; ++i) {
105 const uint8_t b = mv.bytes[i];
106 out.put(hex_digits[(b >> 4) & 0x0F]);
107 out.put(hex_digits[b & 0x0F]);
109 if (sep !=
'\0' && (i + 1) < len) {
Definition microfmt.hpp:881
#define MICROFMT_API_CLASS
Definition compat.hpp:181
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
constexpr mac_view mac(span< const uint8_t > bytes, char separator=':', bool uppercase=false) noexcept
Definition net.hpp:44
constexpr bytes_view bytes(uint64_t count) noexcept
Definition format_helpers.hpp:82