// Author: Wolfgang Bangerth, 2007
+#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
/* ======================== auxiliary functions ================= */
+// Return whether or not one string starts with a given prefix
+bool
+has_prefix(const std::string &base, const std::string &prefix)
+{
+ if (prefix.size() > base.size())
+ return false;
+ else
+ return std::equal(prefix.begin(), prefix.end(), base.begin());
+}
+
// replace all occurrences of 'pattern' by 'substitute' in 'in', and
// return the result
name = get_substring_with_delim (whole_file, " :");
skip_space (whole_file);
- if (whole_file.find (":=") != 0)
+ if (!has_prefix(whole_file, ":="))
{
std::cerr << "Invalid entry <" << name << '>' << std::endl;
std::exit (1);
}
whole_file.erase (0, 2);
skip_space (whole_file);
- if (whole_file.find ("{") != 0)
+ if (whole_file[0] != '{')
{
std::cerr << "Invalid entry <" << name << '>' << std::endl;
std::exit (1);
std::string
expansion = get_substring_with_delim (whole_file, "}");
- if (whole_file.find ("}") != 0)
+ if (whole_file[0] != '}')
{
std::cerr << "Invalid entry <" << name << '>' << std::endl;
std::exit (1);
while (whole_file.size() != 0)
{
skip_space (whole_file);
- if (whole_file.find ("for") != 0)
+ if (!has_prefix(whole_file, "for"))
{
std::cerr << "Invalid instantiation list: missing 'for'" << std::endl;
std::exit (1);
}
whole_file.erase (0, 3);
skip_space (whole_file);
- if (whole_file.find ("(") != 0)
+ if (whole_file[0] != '(')
{
std::cerr << "Invalid instantiation list: missing '('" << std::endl;
std::exit (1);
= split_string_list (get_substring_with_delim (whole_file,
")"),
';');
- if (whole_file.find (")") != 0)
+ if (whole_file[0] != ')')
{
std::cerr << "Invalid instantiation list: missing ')'" << std::endl;
std::exit (1);
// now read the part in {...}
skip_space (whole_file);
- if (whole_file.find ("{") != 0)
+ if (whole_file[0] != '{')
{
std::cerr << "Invalid substitution text" << std::endl;
std::exit (1);
return;
}
// enter subsection
- else if ((line.find ("SUBSECTION ") == 0) ||
- (line.find ("subsection ") == 0))
+ else if (Utilities::match_at_string_start(line, "SUBSECTION ") ||
+ Utilities::match_at_string_start(line, "subsection "))
{
// delete this prefix
line.erase (0, std::string("subsection").length()+1);
subsection_path.push_back (subsection);
}
// exit subsection
- else if ((line.find ("END") == 0) ||
- (line.find ("end") == 0))
+ else if (Utilities::match_at_string_start(line, "END") ||
+ Utilities::match_at_string_start(line, "end"))
{
line.erase (0, 3);
while ((line.size() > 0) && (std::isspace(line[0])))
leave_subsection ();
}
// regular entry
- else if ((line.find ("SET ") == 0) ||
- (line.find ("set ") == 0))
+ else if (Utilities::match_at_string_start(line, "SET ") ||
+ Utilities::match_at_string_start(line, "set "))
{
// erase "set" statement
line.erase (0, 4);
}
}
// an include statement?
- else if ((line.find ("INCLUDE ") == 0) ||
- (line.find ("include ") == 0))
+ else if (Utilities::match_at_string_start(line, "include ") ||
+ Utilities::match_at_string_start(line, "INCLUDE "))
{
// erase "include " statement and eliminate spaces
line.erase (0, 7);