Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
split.hh
Go to the documentation of this file.
1#pragma once
3
4#include <optional>
5#include <string_view>
6
7#include "nix/util/util.hh"
8
9namespace nix {
10
17static inline std::optional<std::string_view> splitPrefixTo(std::string_view & string, char separator)
18{
19 auto sepInstance = string.find(separator);
20
21 if (sepInstance != std::string_view::npos) {
22 auto prefix = string.substr(0, sepInstance);
23 string.remove_prefix(sepInstance + 1);
24 return prefix;
25 }
26
27 return std::nullopt;
28}
29
30static inline bool splitPrefix(std::string_view & string, std::string_view prefix)
31{
32 bool res = hasPrefix(string, prefix);
33 if (res)
34 string.remove_prefix(prefix.length());
35 return res;
36}
37
38} // namespace nix
bool hasPrefix(std::string_view s, std::string_view prefix)
Definition util.cc:234