changeset 27914:a044e50c8dcb

Streamline QRegExp instances in libgu. * file-editor-tab.cc (do_comment_selected_text): Use non-capturing grouping. * octave-qscintilla.cc (smart_indent): Use non-capturing grouping for ekey, mkey, case_key, and stand-alone QRegExp. * octave-qscintilla.cc (smart_indent_line_or_selected_text): Use non-capturing grouping for end_word_regexp, begin_block_regexp, mid_block_regexp, end_block_regexp, case_block_regexp. * qt-interpreter-events.cc (make_filter_list): Use C++ Raw string to define QRegExp with lots of backslashes. * variable-editor.cc (variable_editor_stack::levulUp): Rewrite QRegExp to use character classes to get rid of excessive backslashes.
author Rik <rik@octave.org>
date Mon, 06 Jan 2020 10:18:00 -0800
parents 8df92c17bb5c
children 695bb9322a21
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/octave-qscintilla.cc libgui/src/qt-interpreter-events.cc libgui/src/variable-editor.cc
diffstat 4 files changed, 17 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Jan 04 17:16:59 2020 -0800
+++ b/libgui/src/m-editor/file-editor-tab.cc	Mon Jan 06 10:18:00 2020 -0800
@@ -1526,7 +1526,7 @@
   void file_editor_tab::do_comment_selected_text (bool comment, bool input_str)
   {
     QRegExp rxc;
-    QString ws = "^([ \\t]*)";
+    QString ws = "^(?:[ \\t]*)";
     QStringList comment_str = m_edit_area->comment_string (comment);
     QString used_comment_str = comment_str.at (0);
 
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sat Jan 04 17:16:59 2020 -0800
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Mon Jan 06 10:18:00 2020 -0800
@@ -525,9 +525,9 @@
 
     // last word except for comments,
     // allowing % and # in single or double quoted strings
-    // FIXME This will get confused by transpose.
+    // FIXME: This will get confused by transpose.
     QRegExp ekey = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*"
-                            "(\\w+)[ \t;\r\n]*([%#].*)?$");
+                            "(\\w+)[ \t;\r\n]*(?:[%#].*)?$");
 
     int bpos = bkey.indexIn (prevline, 0);
     int epos;
@@ -550,7 +550,7 @@
 
         if (do_auto_close
             && ! inline_end
-            && ! first_word.contains (QRegExp ("(case|otherwise|unwind_protect_cleanup)")))
+            && ! first_word.contains (QRegExp ("(?:case|otherwise|unwind_protect_cleanup)")))
           {
             // Do auto close
             auto_close (do_auto_close, line, prevline, first_word);
@@ -559,7 +559,7 @@
         return;
       }
 
-    QRegExp mkey = QRegExp ("^[\t ]*(else|elseif|catch|unwind_protect_cleanup)"
+    QRegExp mkey = QRegExp ("^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)"
                             "[\r]?[\t #%\n]");
     if (prevline.contains (mkey))
       {
@@ -576,7 +576,7 @@
         return;
       }
 
-    QRegExp case_key = QRegExp ("^[\t ]*(case|otherwise)[\r]?[\t #%\n]");
+    QRegExp case_key = QRegExp ("^[\t ]*(?:case|otherwise)[\r]?[\t #%\n]");
     if (prevline.contains (case_key) && do_smart_indent)
       {
         QString last_line = text (line-1);
@@ -594,7 +594,7 @@
         setCursorPosition (line+1, act_ind);
       }
 
-    ekey = QRegExp ("^[\t ]*(end|endif|endfor|endwhile|until|endfunction"
+    ekey = QRegExp ("^[\t ]*(?:end|endif|endfor|endwhile|until|endfunction"
                     "|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]");
     if (prevline.contains (ekey))
       {
@@ -618,10 +618,10 @@
     // end[xxxxx] [# comment] at end of a line
     QRegExp end_word_regexp
       = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*"
-                 "(end\\w*)[\r\n\t ;]*([%#].*)?$");
+                 "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$");
 
     QRegExp begin_block_regexp
-      = QRegExp ("^([\t ]*)(if|elseif|else"
+      = QRegExp ("^[\t ]*(?:if|elseif|else"
                  "|for|while|do|parfor"
                  "|switch|case|otherwise"
                  "|function"
@@ -630,13 +630,13 @@
                  "[\r\n\t #%]");
 
     QRegExp mid_block_regexp
-      = QRegExp ("^([\t ]*)(elseif|else"
+      = QRegExp ("^[\t ]*(?:elseif|else"
                  "|otherwise"
                  "|unwind_protect_cleanup|catch)"
                  "[\r\n\t #%]");
 
     QRegExp end_block_regexp
-      = QRegExp ("^([\t ]*)(end"
+      = QRegExp ("^[\t ]*(?:end"
                  "|end(for|function|if|parfor|switch|while"
                  "|classdef|enumeration|events|methods|properties)"
                  "|end_(try_catch|unwind_protect)"
@@ -644,7 +644,7 @@
                  "[\r\n\t #%]");
 
     QRegExp case_block_regexp
-      = QRegExp ("^([\t ]*)(case|otherwise)"
+      = QRegExp ("^[\t ]*(?:case|otherwise)"
                  "[\r\n\t #%]");
 
     int indent_column = -1;
@@ -700,7 +700,8 @@
 
         if (case_block_regexp.indexIn (line_text) > -1)
           {
-            if (case_block_regexp.indexIn (prev_line) < 0 && !prev_line.contains("switch"))
+            if (case_block_regexp.indexIn (prev_line) < 0
+                && !prev_line.contains("switch"))
               indent_column -= indent_increment;
             in_switch = true;
           }
--- a/libgui/src/qt-interpreter-events.cc	Sat Jan 04 17:16:59 2020 -0800
+++ b/libgui/src/qt-interpreter-events.cc	Mon Jan 06 10:18:00 2020 -0800
@@ -84,10 +84,9 @@
         QString ext = QString::fromStdString (ext_name.first);
         QString name = QString::fromStdString (ext_name.second);
 
-        // Strip out extensions from name and replace ';' with spaces in
-        // list.
+        // Strip out extensions from name and replace ';' with spaces in list.
 
-        name.replace (QRegExp ("\\(.*\\)"), "");
+        name.replace (QRegExp (R"(\(.*\))"), "");
         ext.replace (";", " ");
 
         if (name.isEmpty ())
--- a/libgui/src/variable-editor.cc	Sat Jan 04 17:16:59 2020 -0800
+++ b/libgui/src/variable-editor.cc	Mon Jan 06 10:18:00 2020 -0800
@@ -446,7 +446,7 @@
 
     if (name.endsWith (')') || name.endsWith ('}'))
       {
-        name.remove (QRegExp ("(\\(|\\{)[^({]*(\\)|\\})$"));
+        name.remove ( QRegExp ("[({][^({]*[)}]$)") );
         emit edit_variable_signal (name, octave_value ());
       }
   }