12 #include "cetlib_except/coded_exception.h" 20 std::regex
const reCarriageReturn{
"\r"};
22 std::size_t
const include_sz{include_lit.size()};
26 enum error { cant_open, cant_read, malformed };
33 return "Can't locate or can't open specified file:";
35 return "Can't read from supplied input stream:";
37 return "Malformed #include directive:";
39 return "Unknown code";
43 using include_exception = cet::coded_exception<error, translate>;
45 std::vector<std::string>
46 getlines(std::istream& is)
48 std::vector<std::string>
result;
49 for (
std::string readline; std::getline(is, readline);) {
51 result.emplace_back(
line);
66 throw include_exception{cant_read};
68 for (
auto&
line : getlines(in)) {
69 if (
line.find(include_lit) != 0) {
70 result.append(
line).append(1,
'\n');
74 if (
line.end()[-1] !=
'\"')
75 throw include_exception{malformed} <<
line;
78 line.substr(include_sz, line.size() - include_sz - 1)};
79 std::ifstream
f{
fname.c_str(), std::ios_base::in};
81 throw include_exception{cant_open} <<
fname;
97 throw include_exception(cant_read);
99 for (
auto const&
line : getlines(in)) {
100 if (
line.find(include_lit) != 0) {
101 result.append(
line).append(1,
'\n');
105 if (
line.end()[-1] !=
'\"')
106 throw include_exception(malformed) <<
line;
109 line.substr(include_sz,
line.size() - include_sz - 1)};
112 std::ifstream
f{
fname.c_str(), std::ios_base::in};
114 throw include_exception(cant_open) <<
fname;
115 include(
f, search_path_arg, result);
117 std::ifstream
f{paths.find_file(
fname).c_str(), std::ios_base::in};
119 throw include_exception(cant_open)
120 <<
fname <<
"\nusing path: " << paths;
122 include(
f, search_path_arg, result);
std::string & trim_right(std::string &source, std::string const &t=" ")
std::vector< std::string > split_by_regex(std::string const &str, std::regex const &reDelimSet)
std::string translate(errors::ErrorCodes)
bool is_absolute_filepath(std::string const &qualified_filename)
CodeOutputInterface * code
void include(std::istream &in, std::string &result)
void line(double t, double *p, double &x, double &y, double &z)