]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/CDMUtilities.cpp
By Leonardo Florez
[crea.git] / lib / creaDevManagerLib / CDMUtilities.cpp
index 77f5f52cb7b199ec3efb419551f6b7cea640b80a..37f4deb9370e09b7bf2fc7b1130d5ce5ab8f6d1c 100644 (file)
 
 namespace CDMUtilities
 {
-  template <typename Container>
-  Container& splitter::split
-  (
-      Container& result,
-      const typename Container::value_type& s,
-      const typename Container::value_type& delimiters,
-      empties_t empties
-  )
-  {
-    result.clear();
-    size_t current;
-    size_t next = -1;
-    do
-      {
-        if (empties == no_empties)
-          {
-            next = s.find_first_not_of(delimiters, next + 1);
-            if (next == Container::value_type::npos)
-              {
-                break;
-              }
-            next -= 1;
-          }
-        current = next + 1;
-        next = s.find_first_of(delimiters, current);
-        result.push_back(s.substr(current, next - current));
-      }
-    while (next != Container::value_type::npos);
-    return result;
-  }
-
   const std::string fixPath(const std::string& path)
   {
     std::string pathFixed = "";
@@ -356,6 +325,36 @@ namespace CDMUtilities
        return res;
   }
 
+  std::string readFile(const std::string& file_path)
+  {
+    std::string res;
+    std::ifstream file(file_path.c_str());
+    if (file.is_open())
+      {
+        char ch = file.get();
+        while (!file.eof())
+          {
+            res.push_back(ch);
+            ch = file.get();
+          }
+        file.close();
+      }
+    return res;
+  }
+
+  bool writeFile(const std::string& file_path, const std::string& st)
+  {
+    std::ofstream file(file_path.c_str());
+    if (file.is_open())
+      {
+        file << st;
+        file.close();
+        return true;
+      }
+    return false;
+
+  }
+
   CMLFile readCMLFile(const std::string& file_path)
   {
     CMLFile res;
@@ -506,4 +505,16 @@ namespace CDMUtilities
     return false;
   }
 
+
+
+  void
+  normalizeStr(std::string& st)
+  {
+    while(st.size() && isspace(st[0]))
+      st.erase(0,1);
+    while(st.size() && isspace(st[st.size()-1]))
+      st.erase(st.size()-1,1);
+    return;
+  }
+
 }