1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

Add fresh concatStringsSep without bug

The buggy version was previously renamed to
dropEmptyInitThenConcatStringsSep
This commit is contained in:
Robert Hensing 2024-07-12 23:02:08 +02:00
parent 79eb0adf9d
commit a681d354e7
5 changed files with 150 additions and 0 deletions

View file

@ -0,0 +1,31 @@
#pragma once
#include "strings.hh"
namespace nix {
template<class C>
std::string concatStringsSep(const std::string_view sep, const C & ss)
{
size_t size = 0;
bool tail = false;
// need a cast to string_view since this is also called with Symbols
for (const auto & s : ss) {
if (tail)
size += sep.size();
size += std::string_view(s).size();
tail = true;
}
std::string s;
s.reserve(size);
tail = false;
for (auto & i : ss) {
if (tail)
s += sep;
s += i;
tail = true;
}
return s;
}
} // namespace nix