From 1ae00ab0ce03cda302e409db6e5bc9f6a38605ea Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 14 Feb 2010 05:36:42 +0000 Subject: [PATCH] Allow escaping braces. git-svn-id: https://svn.dealii.org/trunk@20615 0785d39b-7218-0410-832d-ea1e28bc413d --- .../common/scripts/expand_instantiations.cc | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/deal.II/common/scripts/expand_instantiations.cc b/deal.II/common/scripts/expand_instantiations.cc index 18cc5fcbb4..ca233ecbd4 100644 --- a/deal.II/common/scripts/expand_instantiations.cc +++ b/deal.II/common/scripts/expand_instantiations.cc @@ -58,17 +58,46 @@ std::map > expansion_lists; /* ======================== auxiliary functions ================= */ + +// replace all occurrences of 'pattern' by 'substitute' in 'in', and +// return the result +std::string +replace_all (const std::string &in, + const std::string &pattern, + const std::string &substitute) +{ + std::string x = in; + while (x.find(pattern) != std::string::npos) + x.replace (x.find(pattern), + pattern.size(), + substitute); + return x; +} + + // extract from the start of #in the part of the string that ends with one of // the characters in #delim_list. The extracted part is deleted from #in +// and returned. We skip characters in delim_list if they are preceded +// by a backslash std::string get_substring_with_delim (std::string &in, const std::string &delim_list) { std::string x; - while ((in.size() != 0) - && - (delim_list.find (in[0]) == std::string::npos)) + while (in.size() != 0) { + // stop copying to the result + // if the current character is + // a delimiter, but only if the + // previous character was not a + // backslash + if ((delim_list.find (in[0]) != std::string::npos) + && + !((x.size() > 0) + && + (x[x.size()-1] == '\\'))) + break; + x += in[0]; in.erase (0, 1); } @@ -377,8 +406,8 @@ void process_instantiations () const std::list substitutions_list = split_string_list (get_substring_with_delim (whole_file, - ")"), - ';'); + ")"), + ';'); if (whole_file.find (")") != 0) { std::cerr << "Invalid instantiation list: missing ')'" << std::endl; @@ -426,8 +455,13 @@ void process_instantiations () whole_file.erase (0,1); skip_space (whole_file); - // now produce the substitutions - substitute (text_to_substitute, substitutions); + // now produce the + // substitutions. first replace + // all occurrences of "\{" by + // "{" + substitute (replace_all(replace_all(text_to_substitute, "\\{", "{"), + "\\}", "}"), + substitutions); } } -- 2.39.5