1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

getSnippetUpTo: Return optional

This makes it possible to certain discern failures from empty
snippets, which I think is an ok review comment.

Maybe it should do so for swapped column indexes too, but I'm not
sure.

I don't think it matters in the grand scheme. We don't even have
a real use case for `nullopt` now anyway.

Since we don't have a use case, I'm not applying this logic to
higher level functions yet.
This commit is contained in:
Robert Hensing 2024-07-15 20:08:41 +02:00
parent 03d33703ef
commit 61a4d3d45c
4 changed files with 10 additions and 8 deletions

View file

@ -110,11 +110,11 @@ void Pos::LinesIterator::bump(bool atFirst)
input.remove_prefix(eol);
}
std::string Pos::getSnippetUpTo(const Pos & end) const {
std::optional<std::string> Pos::getSnippetUpTo(const Pos & end) const {
assert(this->origin == end.origin);
if (end.line < this->line)
return "";
return std::nullopt;
if (auto source = getSource()) {
@ -152,7 +152,7 @@ std::string Pos::getSnippetUpTo(const Pos & end) const {
}
return result;
}
return "";
return std::nullopt;
}