From 8db016c22312438518db5e7c2557be01fc0fd369 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 19 Jul 2015 21:10:20 -0700 Subject: [PATCH] SavePersistent: Sort in name order, fix list commas. --- src/Storage.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Storage.cpp b/src/Storage.cpp index 33d3b2054c..9bf82d0e07 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -170,6 +170,10 @@ void Storage::SavePersistent(std::ostream& os) const { } } + // sort in name order + std::sort(entries.begin(), entries.end(), + [](const auto& a, const auto& b) { return a.first < b.first; }); + std::string base64_encoded; // header @@ -229,10 +233,8 @@ void Storage::SavePersistent(std::ostream& os) const { case NT_BOOLEAN_ARRAY: { bool first = true; for (auto elem : v->GetBooleanArray()) { - if (!first) { - os << ','; - first = false; - } + if (!first) os << ','; + first = false; os << (elem ? "true" : "false"); } break; @@ -240,10 +242,8 @@ void Storage::SavePersistent(std::ostream& os) const { case NT_DOUBLE_ARRAY: { bool first = true; for (auto elem : v->GetDoubleArray()) { - if (!first) { - os << ','; - first = false; - } + if (!first) os << ','; + first = false; os << elem; } break; @@ -251,10 +251,8 @@ void Storage::SavePersistent(std::ostream& os) const { case NT_STRING_ARRAY: { bool first = true; for (auto& elem : v->GetStringArray()) { - if (!first) { - os << ','; - first = false; - } + if (!first) os << ','; + first = false; WriteString(os, elem); } break;