Keep a variable that checks that you are in a valid place for a brace. If it encounters //, it remains false until it reaches \n, if it encounters /*, it remains false until it reaches */, if it encounters \, it remains false for the next char(make sure to allow \\{, when you encounter \, just skip the next char)
Sohguanh, I was not counting the braces, and for that, I would use a simple integer, no need for a stack. I was just saying how to ignore the 3 special cases.
Detroit, when you check a char, if it is \, immediatly skip the next char. This will handle the 2 cases of \{ and \\{ correctly.
Sohguanh, I was not counting the braces, and for that, I would use a simple integer, no need for a stack. I was just saying how to ignore the 3 special cases.
Do you want to just handle the 3 special cases or possibly other more? The more comprehensive solution would be to use Boost RegEx library to help you do such stuff. It is a bit sad Standard C++ does not have any Regular Expression library to help developers out. We have a simple regex in Java libraries though.
What other more cases could their possibly be besides those 3? I'm sure it could be done with regular expressions, but I can only string together fairly basic sequences, what would a regex for the original problem look like?