From 4dfc78f9a244c24f9fc051311f557b185e894543 Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 14 Nov 2008 08:10:04 +0000 Subject: [PATCH] Dump Python extension. --- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 7 ++++--- src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx | 28 +++++++++++++++++++++++++ src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx | 5 +++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index e57143d20..ffedb4437 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -43,6 +43,7 @@ using namespace std; #define DIRECTORYID 16661 #define FILELOCALID 26662 #define FILEID "FILE: " +#define VARIABLE_SEPARATOR ':' //============================================================================ @@ -1744,7 +1745,7 @@ bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStu { string aString = aStringAttr->Value(); - vector aVector = SALOMEDSImpl_Tool::splitString( aString, ':' ); + vector aVector = SALOMEDSImpl_Tool::splitStringWithEmpty( aString, VARIABLE_SEPARATOR ); for( int i = 0, len = aVector.size(); i < len; i++ ) { string aStr = aVector[i]; @@ -1796,7 +1797,7 @@ void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* the bool isChanged = false; string aNewString, aCurrentString = aStringAttr->Value(); - vector aVector = SALOMEDSImpl_Tool::splitString( aCurrentString, ':' ); + vector aVector = SALOMEDSImpl_Tool::splitStringWithEmpty( aCurrentString, VARIABLE_SEPARATOR ); for( int i = 0, len = aVector.size(); i < len; i++ ) { string aStr = aVector[i]; @@ -1807,7 +1808,7 @@ void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* the } aNewString.append( aStr ); - if( i != len ) + if( i != len - 1 ) aNewString.append( ":" ); } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx index fcc1745e8..fcc481455 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -236,6 +236,34 @@ vector SALOMEDSImpl_Tool::splitString(const string& theValue, char separ return vs; } +//============================================================================ +// function : +// purpose : The functions returns a list of substring of initial string +// divided by given separator include empty strings +//============================================================================ +vector SALOMEDSImpl_Tool::splitStringWithEmpty(const string& theValue, char sep) +{ + vector aResult; + if(theValue[0] == sep ) aResult.push_back(string()); + int pos = theValue.find(sep); + if(pos < 0) { + aResult.push_back(theValue); + return aResult; + } + + 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)); + s = s.substr(pos+1, s.size()); + } + + if(!s.empty() && s[0] != sep) aResult.push_back(s); + if(theValue[theValue.size()-1] == sep) aResult.push_back(string()); + + return aResult; +} + void SALOMEDSImpl_Tool::GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds) { diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx index 6019376fb..ea53539fa 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.hxx @@ -61,6 +61,11 @@ public: //The functions returns a list of substring of initial string divided by given separator static std::vector splitString(const std::string& theValue, char separator); + //The functions returns a list of substring of initial string divided by given separator, + //include empty strings + static std::vector splitStringWithEmpty(const std::string& theValue, char separator); + + //Returns a system date static void GetSystemDate(int& year, int& month, int& day, int& hours, int& minutes, int& seconds); -- 2.39.2