|
|
Source code |
1 2 3 4 5 6 7 8 9 |
something before the comment /* comment /*comment in nest*/ */ something after comment |
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 |
int start = str.find("/*");
int pos = start+2;
int b, e;
do {
b = str.find("/*", pos);
e = str.find("*/", pos);
pos = e + 2;
} while( b != -1 && b < e );
if( e != -1) end = pos;
else end = -1;
|
Quoted
Originally posted by antonio.fasolato
Well, the most elegant solution should be using regular expression. I'm not an expert about this topic, but I think it can be done.
|
|
Source code |
1 2 |
comment := '/*' ( text | comment )* '*/' text --- any string that does not contain /* or */ |
Quoted
Originally posted by wysota
This is just a recursive regular expression. The expression has to match the longest string it can find (thus the last closing */) -- yacc works this way. I don't know if QRegExp works like this too.
Quoted
Originally posted by wysota
Look at my code few posts earlier. There is a recursive search inside a loop. Each iteration finds one comment and substitues the string to be search with the content of the comment.
Quoted
/* aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa */
/* aaa aaa aaa /* aaa aaa aaa aaa */ aaa aaa aaa */
/* aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa */
Quoted
From Qt docs:
Note that quantifiers are "greedy". They will match as much text as they can. For example, 0+ will match as many zeros as it can from the first zero it finds, e.g. '2.0005'. Quantifiers can be made non-greedy, see setMinimal().
(no programming language I know of permits this)