/**
* Given a string that contains text
- * separated by commas, split it into its
- * components; for each component, remove
- * leading and trailing spaces.
+ * separated by a #delimiter, split it into
+ * its components; for each component,
+ * remove leading and trailing spaces.
+ *
+ * The default value of the delimiter is a
+ * comma, so that the function splits comma
+ * separated lists of strings.
*/
std::vector<std::string>
- split_comma_separated_list (const std::string &s);
+ split_string_list (const std::string &s,
+ const char delimiter = ',');
/**
* Generate a random number from a
std::vector<std::string>
- split_comma_separated_list (const std::string &s)
+ split_string_list (const std::string &s,
+ const char delimiter)
{
std::string tmp = s;
std::vector<std::string> split_list;
- split_list.reserve (std::count (tmp.begin(), tmp.end(), ',')+1);
+ split_list.reserve (std::count (tmp.begin(), tmp.end(), delimiter)+1);
// split the input list
while (tmp.length() != 0)
std::string name;
name = tmp;
- if (name.find(",") != std::string::npos)
+ if (name.find(delimiter) != std::string::npos)
{
- name.erase (name.find(","), std::string::npos);
- tmp.erase (0, tmp.find(",")+1);
+ name.erase (name.find(delimiter), std::string::npos);
+ tmp.erase (0, tmp.find(delimiter)+1);
}
else
tmp = "";
deallog << Utilities::string_to_int (v)[1] << std::endl;
deallog << Utilities::string_to_int (v)[2] << std::endl;
- const char *p = "alpha, beta, gamma ";
- Assert (Utilities::split_comma_separated_list (p).size() == 3,
- ExcInternalError());
- Assert (Utilities::split_comma_separated_list (p)[0] == "alpha",
- ExcInternalError());
- Assert (Utilities::split_comma_separated_list (p)[1] == "beta",
- ExcInternalError());
- Assert (Utilities::split_comma_separated_list (p)[2] == "gamma",
- ExcInternalError());
+ {
+ const char *p = "alpha, beta, gamma ";
+ Assert (Utilities::split_string_list (p).size() == 3,
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p)[0] == "alpha",
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p)[1] == "beta",
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p)[2] == "gamma",
+ ExcInternalError());
+ }
+
+ {
+ const char *p = "alpha; beta; gamma ";
+ Assert (Utilities::split_string_list (p, ';').size() == 3,
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p, ';')[0] == "alpha",
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p, ';')[1] == "beta",
+ ExcInternalError());
+ Assert (Utilities::split_string_list (p, ';')[2] == "gamma",
+ ExcInternalError());
+ }
deallog << Utilities::generate_normal_random_number (13, 44) << ' ';
deallog << Utilities::generate_normal_random_number (13, 44) << ' ';