From f866401ad17153c6b82b8e57782fa290b5cf7f41 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 22 Sep 2023 17:14:22 +0800 Subject: [PATCH 1/2] Adding set methods --- libstuff/libstuff.cpp | 10 ++++++++++ libstuff/libstuff.h | 1 + 2 files changed, 11 insertions(+) diff --git a/libstuff/libstuff.cpp b/libstuff/libstuff.cpp index 8dbe1a263..9951960f0 100644 --- a/libstuff/libstuff.cpp +++ b/libstuff/libstuff.cpp @@ -654,6 +654,16 @@ list SParseIntegerList(const string& value, char separator) { return valueList; } +// -------------------------------------------------------------------------- +set SParseIntegerSet(const string& value, char separator) { + set valueSet; + list strings = SParseList(value, separator); + for (string str : strings) { + valueSet.insert(SToInt64(str)); + } + return valueSet; +} + // -------------------------------------------------------------------------- bool SParseList(const char* ptr, list& valueList, char separator) { // Clear the input diff --git a/libstuff/libstuff.h b/libstuff/libstuff.h index 5624db2b9..c5afd453c 100644 --- a/libstuff/libstuff.h +++ b/libstuff/libstuff.h @@ -441,6 +441,7 @@ string SEncodeURIComponent(const string& value); // -------------------------------------------------------------------------- // List management list SParseIntegerList(const string& value, char separator = ','); +set SParseIntegerSet(const string& value, char separator = ','); bool SParseList(const char* value, list& valueList, char separator = ','); bool SParseList(const string& value, list& valueList, char separator = ','); list SParseList(const string& value, char separator = ','); From b27bc73983c2d4dc51953e9ff0c5fc8a871b7189 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Sat, 23 Sep 2023 00:40:54 +0800 Subject: [PATCH 2/2] changing to const ref so we don't make copies --- libstuff/libstuff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstuff/libstuff.cpp b/libstuff/libstuff.cpp index 9951960f0..17f17480d 100644 --- a/libstuff/libstuff.cpp +++ b/libstuff/libstuff.cpp @@ -658,7 +658,7 @@ list SParseIntegerList(const string& value, char separator) { set SParseIntegerSet(const string& value, char separator) { set valueSet; list strings = SParseList(value, separator); - for (string str : strings) { + for (const string& str : strings) { valueSet.insert(SToInt64(str)); } return valueSet;