summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-03-07 23:33:03 +0100
committerCarl Hetherington <cth@carlh.net>2024-03-07 23:33:03 +0100
commit04b5957318df591f56e0a5d39720df143dc8230d (patch)
treed241c7d2008e2dad80c989ea2539998b11b12717 /src/lib/util.cc
parent9bebb9724c5b7f254e3cea62a5cdb3c5e0e8571e (diff)
Fix screen name order in KDM emails.
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 7f6e9da5a..fe6602de3 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -1123,3 +1123,31 @@ word_wrap(string input, int columns)
return output;
}
+
+string
+screen_names_to_string(vector<string> names)
+{
+ if (names.empty()) {
+ return {};
+ }
+
+ auto number = [](string const& s) {
+ return s.find_first_not_of("0123456789") == string::npos;
+ };
+
+ if (std::find_if(names.begin(), names.end(), [number](string const& s) { return !number(s); }) == names.end()) {
+ std::sort(names.begin(), names.end(), [](string const& a, string const& b) {
+ return dcp::raw_convert<int>(a) < dcp::raw_convert<int>(b);
+ });
+ } else {
+ std::sort(names.begin(), names.end());
+ }
+
+ string result;
+ for (auto const& name: names) {
+ result += name + ", ";
+ }
+
+ return result.substr(0, result.length() - 2);
+}
+