From 14e116c1d57e1797e7206299d0fdfed2aa03cdf2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 14 Aug 2018 11:31:51 +0200 Subject: Make joinHumanReadable work for input iterators. --- libdevcore/StringUtils.h | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/libdevcore/StringUtils.h b/libdevcore/StringUtils.h index 94c6e3c5..f05a426b 100644 --- a/libdevcore/StringUtils.h +++ b/libdevcore/StringUtils.h @@ -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; -- cgit v1.2.3