Nix 2.93.3
Lix: A modern, delicious implementation of the Nix 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
7namespace nix {
8
15static inline std::optional<std::string_view> splitPrefixTo(std::string_view & string, char separator) {
16 auto sepInstance = string.find(separator);
17
18 if (sepInstance != std::string_view::npos) {
19 auto prefix = string.substr(0, sepInstance);
20 string.remove_prefix(sepInstance+1);
21 return prefix;
22 }
23
24 return std::nullopt;
25}
26
27static inline bool splitPrefix(std::string_view & string, std::string_view prefix) {
28 bool res = string.starts_with(prefix);
29 if (res)
30 string.remove_prefix(prefix.length());
31 return res;
32}
33
34}