1 #ifndef STK_UTIL_DIAG_PreParse_hpp 2 #define STK_UTIL_DIAG_PreParse_hpp 11 #include <boost/regex.hpp> 15 inline bool CaseInSensitiveRegexInFile(
const std::string& regExp,
const std::string& file,
bool debug =
false ) {
16 std::ifstream fileStream(file.c_str());
17 if ( fileStream.bad() ) {
18 std::cerr <<
"Unable to open file " << file << std::endl;
22 re.assign(regExp, boost::regex_constants::icase);
24 if ( boost::regex_search(line,re) ) {
26 std::cout <<
"CaseInSensitiveRegexInFile() found: " << std::endl << line << std::endl;
27 std::cout <<
"CaseInSensitiveRegexInFile() with: " << std::endl << regExp << std::endl;
35 inline std::vector< std::vector< std::string > > ExtractCommandBlocksInFile(
const std::string& beginRegExp,
const std::string& file,
bool debug =
false ) {
36 std::vector< std::vector< std::string > > extractedCommandBlocks;
37 std::vector< std::string > extractedCommandBlock;
38 std::ifstream fileStream(file.c_str());
39 if ( fileStream.bad() ) {
40 std::cerr <<
"Unable to open file " << file << std::endl;
43 boost::regex reBeginStart;
44 reBeginStart.assign(beginRegExp, boost::regex_constants::icase);
46 reBegin.assign(
"^\\s*begin\\>", boost::regex_constants::icase);
48 reEnd.assign(
"^\\s*end\\>", boost::regex_constants::icase);
52 if ( !extract && boost::regex_search(line,reBeginStart) ) {
55 std::cout <<
"ExtractCommandBlocksInFile() started: " << std::endl << line << std::endl;
59 extractedCommandBlock.push_back(line);
60 if ( boost::regex_search(line,reBegin) ) {
62 }
else if ( boost::regex_search(line,reEnd) ) {
67 extractedCommandBlocks.push_back(extractedCommandBlock);
68 extractedCommandBlock.clear();
70 std::cout <<
"ExtractCommandBlocksInFile() stopped: " << std::endl << line << std::endl;
75 return extractedCommandBlocks;
78 std::string CreateSubCycleInputFile(
const std::string& ifile,
bool debug =
false );
82 #endif // STK_UTIL_DIAG_PreParse_hpp
std::istream & getline(std::istream &is, sierra::String &s, char eol)
Function getline returns a string from the input stream which has been terminated by the newline char...