I am attempting to parse a string using regex, so that when I iterate over its matches, it will give me only the results. My goal is to find all
#include <stuff.h>
#include "stuff.h"
while ignoring them if they are part of a comment block such as
/*
#include "stuff.h"
*/
Here is my function to read a file, convert it to string, and parse the string, creating tokens which are then iterated over to print them all. the tokes would contain stuff.h , stuff.h based on the previous lines.
The problem that I ran into was using this regex http://ift.tt/2ownr5d
The question is, is my regex wrong or is it something in the function?
void header_check::filename(const boost::filesystem::directory_iterator& itr) //function takes directory path
{
std::string delimeter ("#include.+(?:<|\\\")(.+)(?:>|\\\")(?![^*\\/]* (?:\\*+(?!\\/)[^*\\/]*|\\/+(?!\\*)[^*\\/]*)*\\*\\/)");//regex storage
boost::regex regx(delimeter,boost::regex::perl);//set up regex
boost::smatch match;
std::ifstream file (itr->path().string().c_str());//stream to transfer to stream
std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());//string to be parsed
boost::sregex_token_iterator iter (content.begin(),content.end(), regx, 0); //creates a match for each search
boost::sregex_token_iterator end;
for (int attempt =1; iter != end; ++iter) {
std::cout<< *iter<<" include #"<<attempt++<<"\n"; //prints results
}
}
Aucun commentaire:
Enregistrer un commentaire