2020-06-30 15:57:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2020-06-30 18:10:30 +00:00
|
|
|
#include <string_view>
|
2020-06-30 15:57:09 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
// If `separator` is found, we return the portion of the string before the
|
|
|
|
// separator, and modify the string argument to contain only the part after the
|
|
|
|
// separator. Otherwise, wer return `std::nullopt`, and we leave the argument
|
|
|
|
// string alone.
|
2020-06-30 18:10:30 +00:00
|
|
|
static inline std::optional<std::string_view> splitPrefix(std::string_view & string, char separator) {
|
2020-06-30 15:57:09 +00:00
|
|
|
auto sepInstance = string.find(separator);
|
|
|
|
|
|
|
|
if (sepInstance != std::string_view::npos) {
|
|
|
|
auto prefix = string.substr(0, sepInstance);
|
|
|
|
string.remove_prefix(sepInstance+1);
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2020-07-02 15:29:33 +00:00
|
|
|
|
2020-06-30 15:57:09 +00:00
|
|
|
}
|