From 007119f47425334d40edf17d5ec1288c77a510a1 Mon Sep 17 00:00:00 2001 From: David Wells Date: Fri, 22 Jan 2016 11:38:46 -0500 Subject: [PATCH] Let FE names have spaces between words. 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 | 3 ++- source/fe/fe_tools.cc | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/deal.II/fe/fe_tools.h b/include/deal.II/fe/fe_tools.h index 4eadc4faa6..98e9612020 100644 --- a/include/deal.II/fe/fe_tools.h +++ b/include/deal.II/fe/fe_tools.h @@ -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 diff --git a/source/fe/fe_tools.cc b/source/fe/fe_tools.cc index f13f1b39cc..aa79fff9d5 100644 --- a/source/fe/fe_tools.cc +++ b/source/fe/fe_tools.cc @@ -50,6 +50,7 @@ #include +#include #include @@ -1547,10 +1548,27 @@ namespace FETools FiniteElement * get_fe_by_name (const std::string ¶meter_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('<')) -- 2.39.5