我想使用eclipse-Indigo生成块注释,如下所示。我是C++程序员。
/**
*
* @param bar
* @return
*/
int foo(int bar);我怎么能这样做呢。
发布于 2012-04-30 16:37:19
如果你的输入是非常静态的,你可以编写一个简化的词法分析器,它可以工作,需要简单的字符串处理。string有很多很好的编辑功能,其中有.substr()和.find()。你要做的就是找出佩伦的下落。您知道,您可以选择将其作为字符串流处理,这使得这一过程变得更加容易(不要忘记使用std::skipws跳过空格。
http://www.cplusplus.com/reference/string/string/substr/
http://www.cplusplus.com/reference/string/string/find/
#include <vector>
#include <string>
typedef STRUCT arg_s {
string sVarArgDataType, sVarArg;
} arg_s ARG;
ARG a;
vector<ARG> va;
char line[65000];
filein.getline(line, 65000);
line[65000-1]='\0'; //force null termination if it hasn't happened
get line and store in string sline0
size_t firstSpacePos=sline.find(' ');
size_t nextSpacePos = sline.find(' ',firstSpacePos+1);
size_t prevCommaPos = string::npos;
size_t nextCommaPos = sline.find(',');
size_t openPerenPos=sline.find('(');
size_t closePerenPos=sline.find(");");
string sReturnDataType, sFuncName;
if (
string::npos==firstSpacePos||
string::npos==semicolonPos||
string::npos==openPerenPos||
string::npos==closePerenPos) {
return false; //failure
}
while (string::npos != nextSpacePos) {
if (string::npos != nextCommaPos) {
//found another comma, a next argument. use next comma as a string terminator and prevCommaPos as an arg beginning.
//assume all keywords are globs of text
a.sVarArgDataType=sline.substr(prevCommaPos+1,nextSpacePos-(prevCommaPos+1));
a.sVarArg=sline.substr(nextSpacePos+1,nextCommaPos-(nextSpacePos+1));
} else {
//didn't find another comma. use ) as a string terminator and prevCommaPos as an arg beginning.
//assume all keywords are globs of text
a.sVarArgDataType=sline.substr(prevCommaPos+1,nextSpacePos-(prevCommaPos+1));
a.sVarArg=sline.substr(nextSpacePos+1,closePerenPos-(nextSpacePos+1));
}
va.push_back(a); //add structure to list
//move indices to next argument
nextCommaPos = sline.find(',', secondSpacePos+1);
nextSpacePos = sline.find(' ', secondSpacePos+1);
}
int i;
fileout<<"/**
*
";
for (i=0; i < va.size(); i++) {
fileout<<" * @param "<<va[i].sVarArg;
}
fileout<<"
* @return
*/
"<<sReturnDataType<<" "<<sFuncName<<'(';
for (i=0; i < va.size(); i++) {
fileout<<va[i].sArgDataType<<" "<<va[i].sVarArg;
if (i != va.size()-1) {
fileout<<", "; //don;t show a comma-space for the last item
}
}
fileout<<");"<<std::endl;它可以处理任意数量的参数,除了...变量参数类型。但您可以为此添加自己的检测代码和if语句,该语句在...和2-关键字参数类型。在这里我只支持两个关键字在我的结构。你可以通过使用while来搜索下一个、逗号或)前的所有空格,在while循环内将你的可变数量的字符串添加到你要替换的结构内的vector<string>中-不,只需生成一个vector<vector<string> >。或者,只有一个向量,在每个函数完成后执行一次va.clear()。
我刚刚注意到了eclipse标签。我对日食了解不多。我甚至不能让它工作。一些程序。
https://stackoverflow.com/questions/10379728
复制相似问题