mardi 26 avril 2016

c++ regex for fetching function signature

I am trying to search a function signature using regex_search in c++. Here's what I am using

std::smatch m;

std::regex e("?(unsigned|signed|const|inline)?\\s?(bool|char|int|float|double|void|wchar_t|string)\\s?[*]?(\\w.*)[(](.*)[)]\\s?{?$");

if(regex_search(xmlFileLine, m, e)) {

cout << xmlFileLine << endl;

}

In the above code 'xmlFileLine' is a string from getline reading each line of the input file. For instance, the string I am trying to match is "int Testo::Fact(int n) {"

When I execute the above regex in try and had all the regex_error flags like paren, complexity and so on... in catch, I got to know it was regex_paren thrown. I am not getting how to resolve it.

Please help me out in this.

Aucun commentaire:

Enregistrer un commentaire