Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_Tool.cxx
index 7f63ea527349869b4984e567c817f21467e1576a..89e9559377992955df9f4d85186a419f86ae8a0c 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  File      : SALOMEDSImpl_Tool.cxx
@@ -31,6 +31,8 @@
 #include <fstream>
 #include <stdlib.h>
 #include <string.h>
+#include <iterator>
+#include <sstream>
 
 #include "SALOMEDSImpl_Tool.hxx"
 
@@ -241,24 +243,66 @@ std::vector<std::string> SALOMEDSImpl_Tool::splitString(const std::string& theVa
 // purpose  : The functions returns a list of substring of initial string 
 //            divided by given separator include empty strings
 //============================================================================
+
+std::vector<std::string> treatRepetation(const std::string& theValue);
+
+std::vector<std::string> treatRepetation(const std::string& theValue)
+{
+  std::vector<std::string> aResult;
+  int pos = theValue.find(";*=");
+  if(pos < 0 )
+    {
+      aResult.push_back(theValue);
+      return aResult;
+    }
+  std::string val(theValue.substr(0, pos));
+  std::string suffix(theValue.substr(pos+3));
+  int nb;
+  std::istringstream tmp(suffix);
+  tmp >> nb;
+  for(int i=0; i<nb; i++)
+    aResult.push_back(val);
+  return aResult;
+}
+
 std::vector<std::string> SALOMEDSImpl_Tool::splitStringWithEmpty(const std::string& theValue, char sep)
 {
   std::vector<std::string> aResult;
   if(theValue[0] == sep ) aResult.push_back(std::string());
   int pos = theValue.find(sep);
   if(pos < 0 ) {
-    aResult.push_back(theValue);
+    if(sep == '|')
+      {
+        std::vector<std::string> tmp = treatRepetation(theValue);
+        std::copy(tmp.begin(), tmp.end(), std::back_insert_iterator< std::vector<std::string> >(aResult));
+      }
+    else
+      aResult.push_back(theValue);
     return aResult;
   }
 
   std::string s = theValue;
   if(s[0] == sep) s = s.substr(1, s.size());
   while((pos = s.find(sep)) >= 0) {
-    aResult.push_back(s.substr(0, pos));
+    if(sep == '|')
+      {
+        std::vector<std::string> tmp = treatRepetation(s.substr(0, pos));
+        std::copy(tmp.begin(), tmp.end(), std::back_insert_iterator< std::vector<std::string> >(aResult));
+      }
+    else
+      aResult.push_back(s.substr(0, pos));
     s = s.substr(pos+1, s.size());
   }
 
-  if(!s.empty() && s[0] != sep) aResult.push_back(s);
+  if(!s.empty() && s[0] != sep) {
+    if(sep == '|')
+      {
+        std::vector<std::string> tmp = treatRepetation(s);
+        std::copy(tmp.begin(), tmp.end(), std::back_insert_iterator< std::vector<std::string> >(aResult));
+      }
+    else
+      aResult.push_back(s);
+  }
   if(theValue[theValue.size()-1] == sep) aResult.push_back(std::string());
 
   return aResult;