Problem of using Boost::regex
I want to make a program to grep all symbols in header file,like: #define CMD_BASE 0x10000000 #define CMD_GETFile (CMD_BASE + 0X00000001) /* Get a file from srv*/ A singl symbole definition line will be extract to three parts: 1. symbol itself 2. the value of a symbol, it's a signed 32-bit value 3. comments about the symbol I use the following pattern: std::string ptn = "\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)"; I hope this pattern could do what I want, but when I use grep to do the parsing, I got from above two lines: what[1]: CMD_BASE what[2]: 0x00001000#define CMD_GET_ALL_DOMAINNAME (CMD_IS_BASE+0x1) you see, the match extend to the new line! I noticed that when I use the same text, same pattern, doing the same thing in a vbscript program, if I set "Global match" option, this wouldn't happen. So, what's the counterpoint at boost::regex? My code here: bool OnGrepSingleLineSymbols(const boost::match_resultsstd::string::const_iterator& what) { Symbol* sym = new Symbol; strcpy(sym->szSymbolName, what[1].str().c_str()); strcpy(sym->szSymbolInfo, what[3].str().c_str()); MakePretty(sym->szSymbolName); MakePretty(sym->szSymbolInfo); sym->nSymbolValue = ResolveMsgValue(sym->szSymbolName, what[2].str()); GetMsgSrv().AddSymbols(sym); return true; } void GrepSingleLineSymbols(CString& strSymContainer) { //#define ARN_SUCCESS 0l //ARRON!'HAHA //#define Arn_error1 ARN_SUCCESS + 0X0F //AARON ERROR1 static std::string ptn = "\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)"; static boost::regex re(ptn); std::string::const_iterator start, end; std::string text = strSymContainer; start = text.begin(); end = text.end(); boost::regex_grep(OnGrepSingleLineSymbols, start, end, re); }
I want to make a program to grep all symbols in header file,like:
#define CMD_BASE 0x10000000 #define CMD_GETFile (CMD_BASE + 0X00000001) /* Get a file from srv*/
A singl symbole definition line will be extract to three parts: 1. symbol itself 2. the value of a symbol, it's a signed 32-bit value 3. comments about the symbol
I use the following pattern: std::string ptn = "\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)";
I hope this pattern could do what I want, but when I use grep to do the parsing, I got from above two lines:
And so you should: the newline is a valid space character, if you don't want to match newlines then use [[:blank:]]+ instead. John.
But I use [^\n]* instead, and this pattern works well in a vbs
script(redundant '\' is removed,of course)
"John Maddock"
I want to make a program to grep all symbols in header file,like:
#define CMD_BASE 0x10000000 #define CMD_GETFile (CMD_BASE + 0X00000001) /* Get a file from srv*/
A singl symbole definition line will be extract to three parts: 1. symbol itself 2. the value of a symbol, it's a signed 32-bit value 3. comments about the symbol
I use the following pattern: std::string ptn = "\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)";
I hope this pattern could do what I want, but when I use grep to do the parsing, I got from above two lines:
And so you should: the newline is a valid space character, if you don't want to match newlines then use [[:blank:]]+ instead.
John.
> But I use [^\n]* instead, and this pattern works well in a vbs > script(redundant '\' is removed,of course) Apologies it's not the \\s+ that's gobbling up the newline: it's the [^/]*. A newline is not a '/' after all, try [^/\n]* instead. John. > "John Maddock"$)ATZNDUBVPLa5=: > >>>I want to make a program to grep all symbols in header file,like: >>> >>> >>> >>> A singl symbole definition line will be extract to three parts: >>> 1. symbol itself >>> 2. the value of a symbol, it's a signed 32-bit value >>> 3. comments about the symbol >>> >>> I use the following pattern: >>> std::string ptn = >>> >>> I hope this pattern could do what I want, but when I use grep to do >>> the parsing, I got from above two lines: >> >>And so you should: the newline is a valid space character, if you don't >>want >>to match newlines then use [[:blank:]]+ instead. >> >>John. > > -------------------------------------------------------------------------------- > _______________________________________________ > Boost-users mailing list > Boost-users@lists.boost.org > http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Aaron
-
John Maddock