Which algorith should I use(Boost::reg_ex)?
I'm writting a program which could evaluate macros in a c++ header file, like this: #define CMD_IS_BASE 0x00001000 #define CMD_GET_ALL_DOMAINNAME (CMD_IS_BASE+0x1) /* Get all domain name from clients*/ After parsing is done, if you input a value(int), the program could tell you the symbol name, symbol meaning (if there is) corresponding to the valude. As to the above example, when you input 1025(or 0x00010001), the program should tell you it's correspond to symbol CMD_GET_ALL_DOMAINNAME, with it's detail comments "get all domain name from clients". I want also this program could parse the following paragraph too: // // MessageId: GL_CAT_SUMMARY // // MessageText: // // Summary%0 // #define GL_CAT_SUMMARY 0x00000002L It's easy to define a regex pattern, then call boost::regex_grep to got all these symbols and their meaning. But what if two formats exist in one header file? I wrote two grepper plug-ins(one is called singleline.dll, the other is McHearder.dll) to find these symbols, which re pattern contains more lines has the high pirioty to be called, then after it's called, the matched string should be erased or be filled with meaningless chars to prevent the later greppers to work on it. See example: The original string: // // MessageId: GL_CAT_SUMMARY // // MessageText: // // Summary%0 // #define GL_CAT_SUMMARY 0x00000002L #define CMD_IS_BASE 0x00001000 First we call McHeader.dll to work on this string, then it grepped: symble:GL_CAT_SUMMARY value: 2 comments:Summary Then the string should be only one lines, ie: #define CMD_IS_BASE 0x00001000 So, how could I achieve that? Could I still use boost::regex_grep? Thanks in advance!
So, how could I achieve that? Could I still use boost::regex_grep?
There are a couple of options: one would be to combine all your regexes into one big expression, each with a different sub-expression index so you can tell which one was matched: (expression-1)|(expression-2)|(expression-3) The other option would be to call regex_grep (which has been deprecated in favour of regex_iterator BTW) with non-constant iterators, then you could fill the area matched with whitespace in preparation for the next match: std::string text(whatever); boost::regex re(expression_text); boost::regex_iteratorstd::string::iterator i(text.begin(), text.end(), re), j; while(i != j) { // do something with *i here, then: std::fill((*i)[0].first, (*i)[0].second, ' '); ++i; } Get the idea? John.
participants (2)
-
Aaron
-
John Maddock