I want to parse a directory tree, find each *.cpp
then eviscerate the functions, leaving me with mocks.
Parsing the tree is no problem. Evisceration is more difficult.
I am currently reading the source file into a string and looping over it character by character. If I see a closed round bracket )
and the next non-whitespace character is an opening brace {
then I have a function start.
Then I can stop writing output, counting opening and closing braces as I go, until I get to the matching end brace }
at the functions end.
The code is horrible and buggy and in constant flux, so hardly worth posting.
Is there an elegant solution, probably involving regex, which will remove the body of all functions in a file, leaving the rest unchanged?
Bonus if it can detect the function's type & generate a return statement, but I can figure that out myself if need be.