aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-14 17:31:51 +0800
committerchriseth <chris@ethereum.org>2018-08-15 00:53:06 +0800
commit14e116c1d57e1797e7206299d0fdfed2aa03cdf2 (patch)
tree4b0449b8f7be9c967ca4a35720397e4673e74442 /libdevcore
parentb30da8859a35065aafed3b2d9aeea5e0941e80c8 (diff)
downloaddexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar.gz
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar.bz2
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar.lz
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar.xz
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.tar.zst
dexon-solidity-14e116c1d57e1797e7206299d0fdfed2aa03cdf2.zip
Make joinHumanReadable work for input iterators.
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/StringUtils.h28
1 files 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;