Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions include/tscpp/util/TextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -1273,21 +1273,47 @@ namespace literals
* std::set<std::string, ts::caseless_compare> strings;
* @endcode
*/
struct caseless_compare {
struct caseless_less_than {
bool
operator()(std::string_view const &lhs, std::string_view const &rhs) const
{
return strcasecmp(lhs, rhs);
return strcasecmp(lhs, rhs) < 0;
}
bool
operator()(TextView const &lhs, TextView const &rhs) const
{
return strcasecmp(lhs, rhs);
return strcasecmp(lhs, rhs) < 0;
}
bool
operator()(std::string const &lhs, std::string const &rhs) const
{
return strcasecmp(lhs, rhs);
return strcasecmp(lhs, rhs) < 0;
}
};

/** Functor for STL containers that need caseless equality of standard string types.
*
* For example a @c std::set of strings with caseless comparison would be
*
* @code
* std::set<std::string, ts::caseless_compare> strings;
* @endcode
*/
struct caseless_equal {
bool
operator()(std::string_view const &lhs, std::string_view const &rhs) const
{
return strcasecmp(lhs, rhs) == 0;
}
bool
operator()(TextView const &lhs, TextView const &rhs) const
{
return strcasecmp(lhs, rhs) == 0;
}
bool
operator()(std::string const &lhs, std::string const &rhs) const
{
return strcasecmp(lhs, rhs) == 0;
}
};

Expand Down
2 changes: 1 addition & 1 deletion iocore/utils/I_Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ struct Machine {
Machine(char const *hostname, sockaddr const *addr);

static self_type *_instance; ///< Singleton for the class.
std::unordered_set<std::string, std::hash<std::string>, ts::caseless_compare> machine_id_strings;
std::unordered_set<std::string, std::hash<std::string>, ts::caseless_equal> machine_id_strings;
std::unordered_set<IpAddr, IpAddr::Hasher> machine_id_ipaddrs;
};
2 changes: 1 addition & 1 deletion iocore/utils/Machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Machine::Machine(char const *the_hostname, sockaddr const *addr)
// limit is 63, or 255 for a FQDN.
auto result = gethostname(localhost, sizeof(localhost));
ink_release_assert(result == 0);
host_name.assign(localhost, result);
host_name.assign(localhost, strlen(localhost));
}

#if HAVE_IFADDRS_H
Expand Down