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:
parent
f77094715f
commit
5dcfddf997
3 changed files with 112 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue