以编程方式识别中的函数体
Function body identification in programmatically
我正在尝试创建一个自动化工具,在函数体上方插入注释行。想法是,我将以文本形式阅读.CPP文件,并找到函数体。一旦在.CPP文件中找到函数体,我就会把函数头放在函数体上面。
文件的读取和写入将类似于普通文本文件,但我想知道广义函数体的定义。也就是说,我将如何以编程方式在.CPP文件中找到函数体。除此之外,还有其他选择,可以将函数头放在函数体之上。
谢谢。
以下是想法:
查找第一个大括号{。然后找到匹配的右大括号。重复
public List<string> FindFunctions(string str)
{
var ret = new List<string>();
var position = 0;
var goout = false;
while (!goout)
{
position = str.IndexOf("{", position);
if (position == -1)
break;
var str1 = GetBracedString(str.Substring(position), '{', '}','"');
position += str1.Length;
ret.Add(str1);
}
return ret;
}
public String GetBracedString(string str, char openB, char closeB, char quoteChar)
{
int i = 0;
var goout = false;
int index = -1;
var isUnpairedQoute = new Func<string, char, bool>((s, q) => s.Count(x => x == q)%2 == 1);
var braceMatch = new Func<string, char, char, bool>((s,o,c) => s.Count(x => x == o) == s.Count(x => x == c));
while (!goout)
{
index = str.IndexOf(closeB, index + 1);
var testS = str.Substring(0, index + 1);
index = isUnpairedQoute(testS,quoteChar) ? str.IndexOf(quoteChar, index) : index;
testS = str.Substring(0, index + 1);
testS = Regex.Replace(testS, String.Format("{0}.*?[{1}{2}]+?.*?{0}", quoteChar, openB, closeB),match => new string('#', match.Value.Length));
goout = braceMatch(testS,openB,closeB);
}
return str.Substring(0, index + 1);
}
相关文章:
- 用C++在单独的头文件中完成函数体
- 我可以在 C++ 中的函数体之外进行操作吗?
- 有没有办法在不使用 #ifdef 的情况下不编译发布版本中的单元测试函数体?
- binary_search() 函数在我的函数体中不起作用
- 如何显示函数开始、结束行和函数体?
- 函数无法识别我在C++传递节点指针向量?
- 主函数体未检测到对重载可变变量模板化函数C++的调用
- 函数的函数无法识别输入参数
- 已定义构造函数的构造函数无法识别
- 模板函数无法识别
- 错误:函数声明符之后的预期函数体
- C++编译器如何检测非常量函数体
- 复制构造函数无法识别继承的成员
- 使用委托调用构造函数和在另一个构造函数体中调用的区别
- Flex和Bison忽略了函数体
- 我看到将我的类成员函数指定为内联实际上会增加执行时间,即使函数体非常小
- 为什么将函数体放置在单独的源代码文件而不是标题中的C/C 中
- 类(模板)成员函数体内部的ADL查找
- 如果未设置编译符号,如何排除方法?如何传递可变数量的参数并在函数体中格式化它们
- 以编程方式识别中的函数体