m_http_client(get_url(url))
{
if (!url.user_info().empty()) {
- const auto [user, password] = util::split_once(url.user_info(), ':');
+ const auto [user, password] =
+ util::split_once_into_views(url.user_info(), ':');
if (!password) {
throw core::Fatal(FMT("Expected username:password in URL but got \"{}\"",
url.user_info()));
} else if (attr.key == "operation-timeout") {
operation_timeout = parse_timeout_attribute(attr.value);
} else if (attr.key == "header") {
- const auto [key, value] = util::split_once(attr.value, '=');
+ const auto [key, value] = util::split_once_into_views(attr.value, '=');
if (value) {
default_headers.emplace(std::string(key), std::string(*value));
} else {
-// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
std::pair<std::optional<std::string>, std::optional<std::string>>
split_user_info(const std::string& user_info)
{
- const auto [left, right] = util::split_once(user_info, ':');
+ const auto [left, right] = util::split_once_into_views(user_info, ':');
if (left.empty()) {
// redis://HOST
return {std::nullopt, std::nullopt};
-// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2025 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
if (parts[i].empty()) {
continue;
}
- const auto [key, right_hand_side] = util::split_once(parts[i], '=');
+ const auto [key, right_hand_side] =
+ util::split_once_into_views(parts[i], '=');
const auto& raw_value = right_hand_side.value_or("true");
const auto value =
util::value_or_throw<core::Error>(util::percent_decode(raw_value));
string, separators, mode, include_delimiter);
}
-std::pair<std::string_view, std::optional<std::string_view>>
-split_once(const char* string, const char split_char)
-{
- return split_once(std::string_view(string), split_char);
-}
-
std::pair<std::string, std::optional<std::string>>
-split_once(std::string&& string, const char split_char)
+split_once(std::string_view string, char split_char)
{
- const auto [left, right] = split_once(std::string_view(string), split_char);
- if (right) {
- return std::make_pair(std::string(left), std::string(*right));
- } else {
- return std::make_pair(std::string(left), std::nullopt);
- }
+ auto [left, right] = split_once_into_views(string, split_char);
+ return std::pair<std::string, std::optional<std::string>>{left, right};
}
std::pair<std::string_view, std::optional<std::string_view>>
-split_once(const std::string_view string, const char split_char)
+split_once_into_views(std::string_view string, char split_char)
{
const size_t sep_pos = string.find(split_char);
if (sep_pos == std::string_view::npos) {
// Split `string` into two parts using `split_char` as the delimiter. The second
// part will be `nullopt` if there is no `split_char` in `string.`
-std::pair<std::string_view, std::optional<std::string_view>>
-split_once(const char* string, char split_char);
std::pair<std::string, std::optional<std::string>>
-split_once(std::string&& string, char split_char);
-std::pair<std::string_view, std::optional<std::string_view>>
split_once(std::string_view string, char split_char);
+// Like `split_once` but splits into `std::string_view`.
+std::pair<std::string_view, std::optional<std::string_view>>
+split_once_into_views(std::string_view string, char split_char);
+
// Split `string` into two parts where the split point is before a potential
// absolute path. The second part will be `nullopt` if no absolute path
// candidate was found.