Skip to content

Commit

Permalink
Make joinHumanReadable work for input iterators.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Aug 14, 2018
1 parent 086e4a3 commit 09bd3b1
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions libdevcore/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,23 @@ std::string joinHumanReadable
std::string const& _lastSeparator = ""
)
{
auto it = begin(_list);
auto itEnd = end(_list);
auto const itEnd = end(_list);

std::string result;

// append first string
if (it != itEnd)
for (auto it = begin(_list); it != itEnd; )
{
result += *it;
std::string element = *it;
bool first = (it == begin(_list));
++it;
}

for (;it != itEnd; ++it)
{
if ((std::next(it) == itEnd) && !_lastSeparator.empty())
result += _lastSeparator; // last iteration
else
result += _separator;

// append string
result += *it;
if (!first)
{
if (it == itEnd && !_lastSeparator.empty())
result += _lastSeparator; // last iteration
else
result += _separator;
}
result += std::move(element);
}

return result;
Expand Down

0 comments on commit 09bd3b1

Please sign in to comment.