...
This commit is contained in:
@@ -304,6 +304,36 @@ public:
|
||||
return proto() == protoMarkWSS;
|
||||
}
|
||||
|
||||
// add '\0' char (or replace special-meaning char/char-sequence) to construct UNIX abstract namespace
|
||||
// endpoint path
|
||||
template <typename T = std::nullptr_t>
|
||||
AdcEndpoint& makeAbstract(const T& mark = nullptr)
|
||||
requires(traits::adc_input_char_range<T> || std::same_as<std::remove_cv_t<T>, char> ||
|
||||
std::is_null_pointer_v<std::remove_cv_t<T>>)
|
||||
{
|
||||
if (!(isLocalStream() || isLocalSeqpacket())) { // only local proto is valid!
|
||||
return *this;
|
||||
}
|
||||
|
||||
if constexpr (std::is_null_pointer_v<T>) { // just insert '\0'
|
||||
auto it = _endpoint.insert(std::string::const_iterator(_path.begin()), '\0');
|
||||
_path = std::string_view(it, _endpoint.end());
|
||||
} else if constexpr (std::same_as<std::remove_cv_t<T>, char>) { // replace a character (mark)
|
||||
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||
if (_endpoint[pos] == mark) {
|
||||
_endpoint[pos] = '\0';
|
||||
}
|
||||
} else { // replace a character range (mark)
|
||||
if (std::ranges::equal(_path | std::views::take(std::ranges::size(mark), mark))) {
|
||||
auto pos = std::distance(_endpoint.cbegin(), std::string::const_iterator(_path.begin()));
|
||||
_endpoint.replace(pos, std::ranges::size(mark), 1, '\0');
|
||||
_path = std::string_view(_endpoint.begin() + pos, _endpoint.end());
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string _endpoint;
|
||||
std::string_view _proto, _host, _path, _portView;
|
||||
|
||||
Reference in New Issue
Block a user