views:

35

answers:

1

A colleague was working on a Perl script to consume a C++ source file and add text above all of the methods in the file. He was looking to develop code using regular expressions from the ground up to detect the top line of the method:

void MyClass::MyMethod(int somethingOrOther)

Trying to do this from scratch is fraught with landmines, like discriminating the method headers from macros, comments, conditionals, etc.

This may be the really, really hard way to do things, as VS 2005 seems to be able to figure out exactly where all of the methods start and end (so that I can click on the box to collapse the method source).

Is there an easy way within the VS 2005 IDE to add some text above each method, solution-wide?

+2  A: 

You can do a regular expression search and replace. Since you can place new lines into replace box, you can go nuts and do anything you want(except for extracting parameters). Example forthcoming.

Search string: ^:b*{:i}:b{:i}\:\:{:i}:b*{\(.*\)}
Replace string: ///Regex Example\n///Class: \2\n///Method: \3 returning \1\n\1 \2::\3\4

Code:

///Regex Example
///Class: Class
///Method: Foo returning void
void Class::Foo(int oneParam)
///Regex Example
///Class: Class
///Method: Bar returning void
void Class::Bar(int noParam)

I am not aware of a method of hooking into Visual Studio parser, unless you write a plugin, which might be a bit of an overkill.

Igor Zevaka
Very cool! I'll be sure to pass this on. Thank you!
John at CashCommons