我试图查看一个 C++ 项目中有多少 goto
指令。现在我正在使用 grep
搜索 "goto "
的简单匹配:
grep -r --exclude-dir "third_party" --include "*.cpp" --include "*.h" --include "*.C" --include "*.cxx" --include "*.hcc" --include "*.c" --include "*.cc" "goto " .
我收到很多假阳性,尤其是内部评论:
// Perform stack overflow check if this goto needs it before jumping.
或内部文字:
stream->Add(" goto (");
避免它们的最简单方法是什么?我不需要完美的解决方案。
最佳答案
将您的正则表达式更改为:'goto[\t]+[_A-Za-z0-9]+[\t]*;'
这将搜索单词 goto,它的目标标签和分号都在同一行。
关于c++ - 查找 C++ 项目中有多少个 goto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15277136/