Bug 100406 - wrong variable detection in code snippets
Summary: wrong variable detection in code snippets
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: general (show other bugs)
Version: 3.1.91
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-27 23:46 UTC by Wilfried Holzke
Modified: 2005-03-08 15:32 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wilfried Holzke 2005-02-27 23:46:13 UTC
Version:           3.1.91 (using KDE KDE 3.3.2)
Installed from:    Gentoo Packages
Compiler:          gcc version 3.3.5  (Gentoo Linux 3.3.5-r1, ssp-3.3.2-3, pie-8.7.7.1) 
OS:                Linux

Using 

$type$ $name$($var1$, $var2$)
{
}

results in a window to type in the replacements for the following variables:

$,$
$name$
$type$

Expected variables and order:

$type$
$name$
$var1$
$var2$
Comment 1 Robert Gruber 2005-03-08 15:16:11 UTC
CVS commit by rgruber: 

* Fixed crashing if only a double-delimiter exists in the snippet.
* Also extended regexp-search to allow variables which contains numbers.
  Variablenames may only contain the following characters: 
  A-Z, a-z, 0-9, -, _ and <blank>

BUGS:100332
BUGS:100406


  M            snippet_widget.cpp   1.25


--- kdevelop/parts/snippet/snippet_widget.cpp  #1.24:1.25
@@ -596,24 +596,28 @@ QString SnippetWidget::parseText(QString
 
   do {
-    iFound = text.find(QRegExp("\\"+del+"[A-Z,a-z,\\s]*\\"+del), iEnd+1);  //find the next variable by this QRegExp
+    iFound = text.find(QRegExp("\\"+del+"[A-Za-z-_0-9\\s]*\\"+del), iEnd+1);  //find the next variable by this QRegExp
     if (iFound >= 0) {
       iEnd = text.find(del, iFound+1)+1;
       strName = text.mid(iFound, iEnd-iFound);
 
-      if ( strName != del+del  &&  mapVar[strName].length() <= 0 ) {  //if not doubel-delimiter and not already in map
-        if (iInMeth == 0) {  //check config, if input-method "single" is selected
+      if ( strName != del+del  ) {  //if not doubel-delimiter 
+        if (iInMeth == 0) { //if input-method "single" is selected
+          if ( mapVar[strName].length() <= 0 ) {  // and not already in map
           strMsg=i18n("Please enter the value for <b>%1</b>:").arg(strName);
           strNew = showSingleVarDialog( strName, &_mapSaved, rSingle );
           if (strNew=="")
             return ""; //user clicked Cancle
+          } else {
+            continue; //we have already handled this variable
         }
       } else {
-        strNew = del;
+          strNew = ""; //for inputmode "multi" just reset new valaue
+        }
+      } else {
+        strNew = del; //if double-delimiter -> replace by single character
       }
 
-      if (iInMeth == 0  ||  strName == del+del) {  //check config, if input-method "single" is selected
+      if (iInMeth == 0) {  //if input-method "single" is selected
         str.replace(strName, strNew);
-      } else {
-        strNew = strName;
       }
 
@@ -750,5 +754,7 @@ bool SnippetWidget::showMultiVarDialog(Q
     dlg.setGeometry(r);
   }
-  if ( dlg.exec() == QDialog::Accepted ) {
+  if ( i > 0 && // only if there are any variables
+    dlg.exec() == QDialog::Accepted ) {
+
     QMap<QString, KTextEdit *>::Iterator it2;
     for ( it2 = mapVar2Te.begin(); it2 != mapVar2Te.end(); ++it2 ) {
@@ -783,4 +789,7 @@ bool SnippetWidget::showMultiVarDialog(Q
   delete layout;
 
+  if (i==0) //if nothing happened this means, that there are no variables to translate
+    return true; //.. so just return OK
+
   return bReturn;
 }


Comment 2 Matt Rogers 2005-03-08 15:32:55 UTC
CVS commit by mattr: 

Backport the fixes for bugs 100332 and 100406 (revision 1.25)

Should be in KDevelop 3.2.1

CCBUGS: 100332, 100406


  M +22 -13    snippet_widget.cpp   1.23.2.1


--- kdevelop/parts/snippet/snippet_widget.cpp  #1.23:1.23.2.1
@@ -596,24 +596,28 @@ QString SnippetWidget::parseText(QString
 
   do {
-    iFound = text.find(QRegExp("\\"+del+"[A-Z,a-z,\\s]*\\"+del), iEnd+1);  //find the next variable by this QRegExp
+    iFound = text.find(QRegExp("\\"+del+"[A-Za-z-_0-9\\s]*\\"+del), iEnd+1);  //find the next variable by this QRegExp
     if (iFound >= 0) {
       iEnd = text.find(del, iFound+1)+1;
       strName = text.mid(iFound, iEnd-iFound);
 
-      if ( strName != del+del  &&  mapVar[strName].length() <= 0 ) {  //if not doubel-delimiter and not already in map
-        if (iInMeth == 0) {  //check config, if input-method "single" is selected
+      if ( strName != del+del  ) {  //if not doubel-delimiter 
+        if (iInMeth == 0) { //if input-method "single" is selected
+          if ( mapVar[strName].length() <= 0 ) {  // and not already in map
           strMsg=i18n("Please enter the value for <b>%1</b>:").arg(strName);
           strNew = showSingleVarDialog( strName, &_mapSaved, rSingle );
           if (strNew=="")
             return ""; //user clicked Cancle
+          } else {
+            continue; //we have already handled this variable
         }
       } else {
-        strNew = del;
+          strNew = ""; //for inputmode "multi" just reset new valaue
+        }
+      } else {
+        strNew = del; //if double-delimiter -> replace by single character
       }
 
-      if (iInMeth == 0  ||  strName == del+del) {  //check config, if input-method "single" is selected
+      if (iInMeth == 0) {  //if input-method "single" is selected
         str.replace(strName, strNew);
-      } else {
-        strNew = strName;
       }
 
@@ -750,5 +754,7 @@ bool SnippetWidget::showMultiVarDialog(Q
     dlg.setGeometry(r);
   }
-  if ( dlg.exec() == QDialog::Accepted ) {
+  if ( i > 0 && // only if there are any variables
+    dlg.exec() == QDialog::Accepted ) {
+
     QMap<QString, KTextEdit *>::Iterator it2;
     for ( it2 = mapVar2Te.begin(); it2 != mapVar2Te.end(); ++it2 ) {
@@ -783,4 +789,7 @@ bool SnippetWidget::showMultiVarDialog(Q
   delete layout;
 
+  if (i==0) //if nothing happened this means, that there are no variables to translate
+    return true; //.. so just return OK
+
   return bReturn;
 }