summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Schlosser <christoph@linux.com>2017-10-15 21:29:09 +0200
committerChristoph Schlosser <christoph@linux.com>2017-10-15 21:29:09 +0200
commit8f627c5afcf4a959cf3937d6c89732745eebbbb8 (patch)
treefc0c8586dee0ad6ccc7dcd0eecc87d62dc57f34c
parentc7ebe707bbfbe52c75646a111600986d6c584d03 (diff)
downloaddoxdocgen-8f627c5afcf4a959cf3937d6c89732745eebbbb8.tar.gz
Fix param generation for function pointers
Fixes #10
-rw-r--r--src/CodeParser/CParser.ts39
-rw-r--r--src/DocGen/CGen.ts9
2 files changed, 40 insertions, 8 deletions
diff --git a/src/CodeParser/CParser.ts b/src/CodeParser/CParser.ts
index 8b0bfe1..f26aa5f 100644
--- a/src/CodeParser/CParser.ts
+++ b/src/CodeParser/CParser.ts
@@ -70,8 +70,7 @@ export default class CParser implements ICodeParser {
logicalLine += nextLineTxt;
// Get method end line
- while (nextLineTxt.indexOf(")") === -1 &&
- (nextLineTxt.indexOf(";") === -1 || nextLineTxt.indexOf("}") === -1)) { // Check for method end
+ while (nextLineTxt.indexOf(";") === -1 && nextLineTxt.indexOf("{") === -1) { // Check for method end
nextLine = new Position(nextLine.line + 1, nextLine.character);
nextLineTxt = this.activeEditor.document.lineAt(nextLine.line).text.trim();
@@ -118,20 +117,50 @@ export default class CParser implements ICodeParser {
protected getParams(method: string): string[] {
const params: string[] = [];
+ const endOfCtorIdx: number = method.search(/\)\s*:/g);
+
+ let func: string = "";
+
+ if (endOfCtorIdx !== -1) {
+ func = method.substring(0, endOfCtorIdx + 1);
+ } else {
+ func = method;
+ }
+
// Get parameters from enclosing brackets
- const parameters: string = method.slice(method.indexOf("(")) // Get opening bracket
- .slice(1, method.indexOf(")")) // Remove opening bracket
- .split(")")[0]; // Get closing bracket
+ const parameters: string = func.substring(func.indexOf("(") + 1, // Get text after opening bracket
+ func.lastIndexOf(")")); // Remove closing bracket
if (parameters.length === 0) { // No parameters
return params;
}
+ let functionPointer: boolean = false;
+
let paramArr: string[] = parameters.split(",");
paramArr = paramArr.map((item: string) => {
// Remove any special C++ characters
const clean: string = item.trim().replace(/[&*\[\]]/g, "");
+ // function pointer special case
+ if (item.indexOf("(") !== -1) {
+ if (item.indexOf(")") !== -1) {
+ // Get the name of the function pointer
+ const funPtr: string = clean.substring(item.indexOf("("), item.indexOf(")"))
+ .replace(/[()]/g, ""); // Remove the brackets
+
+ functionPointer = true;
+ return funPtr.trim();
+ }
+ return null;
+ }
+
+ // Ignore all params until the closing bracket of the function pointer params
+ if (item.indexOf(")") !== -1 && functionPointer) {
+ functionPointer = false;
+ return null;
+ }
+
return clean.split(" ").pop();
});
diff --git a/src/DocGen/CGen.ts b/src/DocGen/CGen.ts
index c2750ee..e333014 100644
--- a/src/DocGen/CGen.ts
+++ b/src/DocGen/CGen.ts
@@ -108,9 +108,12 @@ export default class CGen implements IDocGen {
let line: string = "";
templateWith.forEach((element: string) => {
- line = this.commentPrefix;
- line += this.getTemplatedString(replace, template, element);
- lines.push(line);
+ // Ignore null values
+ if (element !== null) {
+ line = this.commentPrefix;
+ line += this.getTemplatedString(replace, template, element);
+ lines.push(line);
+ }
});
}