1

我想在我的 c++ Visual Studio 2015 项目中的每个函数的开头添加一行代码。

在每个函数中手动添加一行需要几个月的时间。有没有快速的方法或工具来解决这个问题?

函数示例有:

void Class::Func1(CATUnicodeString& Record ) const{ //some code }

Class1::Class1():CATBaseUnknown() ,_usDrawingNumber( "" ){ //some code }

Class1::~Class1() { //some code }

我需要处理所有这些函数定义

样本:

void func1() 
{
    //code
}

int func2() 
{
    //code
}

char* func3() 
{
    //code
}

/* more functions */

bool func100()
{
    //code
}


//I want them to become:

void func1() 
{
    myMacro;
    //code
}

int func2() 
{
    myMacro;
    //code
}

char* func3() 
{
    myMacro;
    //code
}

/* more functions */

bool func100() 
{
    myMacro;
    //code
}

我找到了类似的答案来解释正则表达式、方面编程、__pender。由于我是初学者,很难理解这些概念。

期望是:我想提供工作区文件夹的路径,工具将获取其中的所有 cpp 文件并在所需位置添加宏。

如果此工具不存在,请指导是否可以使用.net、java或python等任何技术构建类似的工具。

4

1 回答 1

0

替换(^.*\(.*\).*\n{)\n(.*)$1\nmyMacro\n$2


解释:

1st Capturing Group (^.*\(.*\).*\n{):
^ asserts position at start of a line
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\( matches the character ( literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\) matches the character ) literally (case sensitive)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
{ matches the character { literally (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)  

2nd Capturing Group (.*):
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed

演示

RE:I found similar answers explaining about regex,aspect programming,__pender. As I am a beginner, its hard to understand those concepts.
在 Visual Studio 中使用查找替换;)

演示中链接的站点还提供了一个C#/python可以稍作修改的代码,可以用作转换所需文件的“工具”

于 2020-07-24T03:56:45.937 回答