diff OrthancFramework/Sources/Toolbox.cpp @ 5373:123a94dd57df

Toolbox::SplitString
author Alain Mazy <am@osimis.io>
date Thu, 17 Aug 2023 17:25:08 +0200
parents 7cb1b851f5c8
children daf4807631c5
line wrap: on
line diff
--- a/OrthancFramework/Sources/Toolbox.cpp	Thu Aug 17 11:25:59 2023 +0200
+++ b/OrthancFramework/Sources/Toolbox.cpp	Thu Aug 17 17:25:08 2023 +0200
@@ -1035,10 +1035,10 @@
     return result;
   }
 
-
-  void Toolbox::TokenizeString(std::vector<std::string>& result,
+  static void TokenizeStringInternal(std::vector<std::string>& result,
                                const std::string& value,
-                               char separator)
+                               char separator,
+                               bool includeEmptyStrings)
   {
     size_t countSeparators = 0;
     
@@ -1068,7 +1068,41 @@
       }
     }
 
-    result.push_back(currentItem);
+    if (includeEmptyStrings || !currentItem.empty())
+    {
+      result.push_back(currentItem);
+    }
+  }
+
+
+  void Toolbox::TokenizeString(std::vector<std::string>& result,
+                               const std::string& value,
+                               char separator)
+  {
+    TokenizeStringInternal(result, value, separator, true);
+  }
+
+
+  void Toolbox::SplitString(std::set<std::string>& result,
+                            const std::string& value,
+                            char separator)
+  {
+    result.clear();
+
+    std::vector<std::string> temp;
+    TokenizeStringInternal(temp, value, separator, false);
+    for (size_t i = 0; i < temp.size(); ++i)
+    {
+      result.insert(temp[i]);
+    }
+  }
+
+
+  void Toolbox::SplitString(std::vector<std::string>& result,
+                            const std::string& value,
+                            char separator)
+  {
+    TokenizeStringInternal(result, value, separator, false);
   }