0

e.g. In my legacy code, there are lots of template usages. But I refactored the code base to limit the template usage only in base classes. Then here comes the problem, Is there a fast way (using find and replace, maybe) to change:

"SomeTemplate<some_var>" into just "some_var" ?

Thanks a lot!

4

1 回答 1

0

In Find and Replace, expand Find Options and tick Use Regular Expressions then replace:

SomeTemplate\<{:i}\>

with

\1

The {} tags the group and :i matches a C++ identifier. The \1 references the first tagged group.

EDIT: If you also have namespaces then you'll need a more complex regular expression. If you know that you have at most one level of namespace then probably the quickest thing to do is just do a second pass to replace:

SomeTemplate\<{:i}\:\:{:i}\>

with

\1::\2

Note that because ':', '<' and '>' have a special meaning in regular expressions they have to be escaped with a backslash.

于 2012-08-13T09:31:18.333 回答