]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Let FE names have spaces between words.
authorDavid Wells <wellsd2@rpi.edu>
Fri, 22 Jan 2016 16:38:46 +0000 (11:38 -0500)
committerDavid Wells <wellsd2@rpi.edu>
Fri, 5 Feb 2016 03:59:15 +0000 (22:59 -0500)
Previously, things like

    FESystem[FE_Q(1) - FE_Q(2)]

caused parsing errors due to the spaces around the '-'. The new behavior is to
delete space that is not surrounded by 'word' characters (things that match the
regular expression [A-Za-z0-9_]) before parsing the name.

include/deal.II/fe/fe_tools.h
source/fe/fe_tools.cc

index 4eadc4faa6fcd41ae37b498cdea8e139c1e3d695..98e9612020a52696b8cb15b5deeece18feddd053 100644 (file)
@@ -845,7 +845,8 @@ namespace FETools
 
   /**
    * Parse the name of a finite element and generate a finite element object
-   * accordingly.
+   * accordingly. The parser ignores space characters between words (things
+   * matching the regular expression [A-Za-z0-9_]).
    *
    * The name must be in the form which is returned by the
    * FiniteElement::get_name function, where dimension template parameters
index f13f1b39cc6e1bddddc8de96f34f63d5ccd9310c..aa79fff9d5b68e9567693f9e90c52328f8b1dbff 100644 (file)
@@ -50,6 +50,7 @@
 
 #include <deal.II/base/index_set.h>
 
+#include <cctype>
 #include <iostream>
 
 
@@ -1547,10 +1548,27 @@ namespace FETools
   FiniteElement<dim, spacedim> *
   get_fe_by_name (const std::string &parameter_name)
   {
+    std::string name = Utilities::trim(parameter_name);
+    std::size_t index = 1;
+    // remove spaces that are not between two word (things that match the
+    // regular expression [A-Za-z0-9_]) characters.
+    while (2 < name.size() && index < name.size() - 1)
+      {
+        if (name[index] == ' ' &&
+            (!(std::isalnum(name[index - 1]) || name[index - 1] == '_') ||
+             !(std::isalnum(name[index + 1]) || name[index + 1] == '_')))
+          {
+            name.erase(index, 1);
+          }
+        else
+          {
+            ++index;
+          }
+      }
+
     // Create a version of the name
     // string where all template
     // parameters are eliminated.
-    std::string name = parameter_name;
     for (unsigned int pos1 = name.find('<');
          pos1 < name.size();
          pos1 = name.find('<'))

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.