Salome HOME
A constructor and destructor added.
authorasv <asv@opencascade.com>
Mon, 10 Jan 2005 10:43:27 +0000 (10:43 +0000)
committerasv <asv@opencascade.com>
Mon, 10 Jan 2005 10:43:27 +0000 (10:43 +0000)
A bug was fixed: replacement of ALL occurances of function name in the node's code, NOT only in "def Func_Name():" line.

src/SUPERVGUI/SUPERVGUI_Clipboard.cxx

index 6b2f500750c4ae80ef2299db346b9a3e2d0e05f2..0ab4c7a29a5a55350173b6ee8ab20a9f548cf6c0 100644 (file)
@@ -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).