help you to create the function headers comment

Ask questions about how to create a script or swap scripts with other users.
Post Reply
richardy
Posts: 2
Joined: 14 Oct 2009 08:32

help you to create the function headers comment

Post by richardy »

if you have write some functions, and you need write a comments for the function, it's just for you. what you want to do just modify the text in red for your function comments specification.

if you like it, so you can leave some messages.

functioncomments.cpp
------------------------------------
bool ParseKVStr(string sKVStr, string& key, string& value, string splitchar=" ")
{
result = false;
int curr_pos = pos(splitchar, sKVStr);
if (curr_pos != 0)
{
key = copy(sKVStr, 0, curr_pos);
value = trim(copy(sKVStr, curr_pos + length(splitchar), length(sKVStr)));
result = true;
}
return result;
}

void ParseFuncDefinion(string funcDefText, string& sRetType, string& sFuncName, TStrings& oParamList)
{
int pos1 = Pos(" ", funcDefText);
int pos2 = Pos(" *", funcDefText);
int pos3 = Pos("(", funcDefText);
int pos4 = Pos(")", funcDefText);

//get the type and name of function
int curr_pos = 0;
if (pos2 != 0)
{
if (pos2 < pos3)
{
insert(" ", funcDefText, pos2 + 2);
deletestr(funcDefText, pos1, pos2 - pos1 + 1);
pos3 = Pos("(", funcDefText);
pos4 = Pos(")", funcDefText);
}
}

string sKVStr = copy(funcDefText, 0, pos3 - 1);
ParseKVStr(sKVStr, sRetType, sFuncName);

sKVStr = trim(copy(funcDefText, pos3 + 1, pos4 - pos3 - 1));
if (sKVStr == "") return;
if (sKVStr == "void") return;
string sKey, sValue;
string sParamType, sParamName;
while (ParseKVStr(sKVStr, sKey, sValue, ","))
{
sKVStr = sValue;
ParseKVStr(sKey, sParamType, sParamName);
oParamList.Add(sParamName + "=" + sParamType);
}
ParseKVStr(sKVStr, sParamType, sParamName);
oParamList.Add(sParamName + "=" + sParamType);
}

string GenerateCppFunctionComments(string funcText)
{
string sRetType;
string sFuncName;
TStrings oParamList = new TStringList;
ParseFuncDefinion(funcText, sRetType, sFuncName, oParamList);
result = "//==================================================================" + chr(13) + chr(10)
+ "// Name : " + sFuncName + chr(13) + chr(10)
+ "// Author : " + chr(13) + chr(10)
+ "// Date : " + DateTimeToStr(Now()) + chr(13) + chr(10)
+ "// function : " + chr(13) + chr(10)
+ "// Parameter: " + chr(13) + chr(10);
for (int i = 0; i < oParamList.count; i++)
result = result + "// " + oParamList.Names(i) + chr(13) + chr(10);
result = result + "// return :" + chr(13) + chr(10);
result = result + "//" + chr(13) + chr(10);
result = result + "//==================================================================";

return result;
}

void AddFunctionComments()
{
string funcText;
string functionComment;
Document.CursorDocStart(true);
while (Document.GotoNextMethod(false))
{
Document.GetMethodAtCursor(false);
Document.SelectCurrentLine();
funcText = Document.SelText;
functionComment = GenerateCppFunctionComments(funcText);
Document.CursorUp(false);
Document.CursorLineStart(false);
Document.InsertText(functionComment);
Document.CursorDown(false);
}
}

{
AddFunctionComments;
}
Post Reply