16 explicit Domain(std::string_view dom
) { set(dom
); }
18 Domain
& operator=(std::string_view dom
)
24 void set(std::string_view dom
);
28 bool empty() const { return ascii_
.empty(); }
30 inline static std::string_view
remove_trailing_dot(std::string_view a
);
31 inline static bool match(std::string_view a
, std::string_view b
);
33 bool operator==(std::string_view rhs
) const { return match(ascii_
, rhs
); }
34 bool operator!=(std::string_view rhs
) const { return !(*this == rhs
); }
36 bool operator==(Domain
const& rhs
) const { return match(ascii_
, rhs
.ascii_
); }
37 bool operator!=(Domain
const& rhs
) const { return !(*this == rhs
); }
39 bool is_address_literal() const { return is_address_literal_
; }
40 bool is_unicode() const { return utf8() != ascii(); }
42 std::string
const& ascii() const { return ascii_
; }
43 std::string
const& utf8() const { return utf8_
; }
45 static bool validate(std::string_view dom
);
51 bool is_address_literal_
{false};
54 inline void Domain::clear()
58 is_address_literal_
= false;
61 inline std::string_view
Domain::remove_trailing_dot(std::string_view a
)
63 if (a
.length() && (a
.back() == '.')) {
69 inline bool Domain::match(std::string_view a
, std::string_view b
)
71 return iequal(remove_trailing_dot(a
), remove_trailing_dot(b
));
74 inline std::ostream
& operator<<(std::ostream
& os
, Domain
const& dom
)
77 return os
<< '{' << dom
.ascii() << ',' << dom
.utf8() << '}';
78 return os
<< dom
.ascii();
84 std::size_t operator()(Domain
const& k
) const
86 return hash
<std::string
>()(k
.ascii());
91 #endif // DOMAIN_DOT_HPP