From 77f486a07b69c0518fd620dbe18e72d7d973e4f9 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 4 Jul 2021 16:35:11 +0200 Subject: [PATCH] putil: Improve SparseArray output printing --- panda/src/putil/sparseArray.cxx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/panda/src/putil/sparseArray.cxx b/panda/src/putil/sparseArray.cxx index 5404728aa1..450cc5a6b3 100644 --- a/panda/src/putil/sparseArray.cxx +++ b/panda/src/putil/sparseArray.cxx @@ -215,21 +215,28 @@ has_bits_in_common(const SparseArray &other) const { */ void SparseArray:: output(std::ostream &out) const { + if (_subranges.empty()) { + out << (_inverse ? "[ all ]" : "[ ]"); + return; + } out << "[ "; if (_inverse) { out << "all except: "; } Subranges::const_iterator si; for (si = _subranges.begin(); si != _subranges.end(); ++si) { + if (si != _subranges.begin()) { + out << ", "; + } if ((*si)._end == (*si)._begin + 1) { // A single element. - out << (*si)._begin << ", "; + out << (*si)._begin; } else { // A range of elements. - out << (*si)._begin << "-" << ((*si)._end - 1) << ", "; + out << (*si)._begin << "-" << ((*si)._end - 1); } } - out << "]"; + out << " ]"; } /**