From: asv Date: Mon, 10 Jan 2005 10:43:27 +0000 (+0000) Subject: A constructor and destructor added. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3499b168bc10e6b88578e315d70162bef477d249;p=modules%2Fsuperv.git A constructor and destructor added. A bug was fixed: replacement of ALL occurances of function name in the node's code, NOT only in "def Func_Name():" line. --- diff --git a/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx b/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx index 6b2f500..0ab4c7a 100644 --- a/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Clipboard.cxx @@ -48,23 +48,26 @@ QString getNewName( QStringList& allNames, const QString& oldName ) { } /** - * Replaces "def*origName*" string with "def*newName*" string + * Replaces origName string with newName string in all lines of theFunc + * origName must be preceeded by space and end by space or '('. */ bool replaceName( SUPERV::ListOfStrings_var& theFunc, const QString& origName, const QString& newName ) { - // asv : 30.12.04 : it's a mistake to replace all function_name-s in all function_strings. - // must be only in "def XXX():", with "do-while" I want to skip all empty and comment lines.. - int i( 0 ), index( -1 ); - do { + for ( int i = 0, n = theFunc->length(); i < n; i++ ) { QString aLine( theFunc[i] ); - index = aLine.find(origName); - if ( index >= 0 && aLine.startsWith( "def" ) ) { // looking for "def*origName*" - theFunc[i] = aLine.replace( index, origName.length(), newName ).latin1(); - return true; + int index = aLine.find( origName, 0 ); // find FIRST occurance of origName in aLine + while ( index >= 0 ) { + bool preceedingCharOk = ( index==0 || ( index > 0 && aLine[index-1].isSpace() ) ); + const int ll = aLine.length(); + const int ol = origName.length(); + const int ni = index + ol; + bool nextCharOk = ( ll==ni || ( ll>ni && ( aLine[ni].isSpace() || aLine[ni]=='(' ) ) ); + if ( preceedingCharOk && nextCharOk ) { + aLine = aLine.replace( index, origName.length(), newName ); + theFunc[i] = aLine.latin1(); + } + index = aLine.find( origName, index+newName.length() ); // find NEXT occurance of origName in aLine } - i++; } - while ( i < theFunc->length() ); - return false; } /** @@ -85,6 +88,19 @@ void copyPorts( const SUPERV::CNode_var& fromNode, const SUPERV::INode_var& toNo } } +/** + * Constructor + */ +SUPERVGUI_Clipboard::SUPERVGUI_Clipboard( QObject* parent ) +: QObject( parent ) { +} + +/** + * Destructor + */ +SUPERVGUI_Clipboard::~SUPERVGUI_Clipboard() { +} + /** * Called on Paste Node command. Inserts a new node to the dataflow equal to the copied node. * For InLine nodes the Python function name is changed ("_N" added).