mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Create the spitPrefix function in parser.hh
This commit is contained in:
parent
a83566e5bc
commit
7ba0fae0dd
1 changed files with 25 additions and 0 deletions
25
src/libutil/parser.hh
Normal file
25
src/libutil/parser.hh
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
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.
|
||||
std::optional<std::string_view> splitPrefix(std::string_view & string, char separator);
|
||||
|
||||
std::optional<std::string_view> splitPrefix(std::string_view & string, char separator) {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue