1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-17 16:02:43 +01:00

strings: Add optionalBracket helper

This commit is contained in:
Robert Hensing 2025-10-13 13:59:39 +02:00
parent f77094715f
commit 5dcfddf997
3 changed files with 112 additions and 0 deletions

View file

@ -138,4 +138,18 @@ std::list<std::string> shellSplitString(std::string_view s)
return result;
}
std::string optionalBracket(std::string_view prefix, std::string_view content, std::string_view suffix)
{
if (content.empty()) {
return "";
}
std::string result;
result.reserve(prefix.size() + content.size() + suffix.size());
result.append(prefix);
result.append(content);
result.append(suffix);
return result;
}
} // namespace nix