diff options
| author | Christoph Schlosser <christoph@linux.com> | 2017-10-15 21:29:09 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2017-10-15 21:29:09 +0200 |
| commit | 8f627c5afcf4a959cf3937d6c89732745eebbbb8 (patch) | |
| tree | fc0c8586dee0ad6ccc7dcd0eecc87d62dc57f34c /src/CodeParser | |
| parent | c7ebe707bbfbe52c75646a111600986d6c584d03 (diff) | |
| download | doxdocgen-8f627c5afcf4a959cf3937d6c89732745eebbbb8.tar.gz | |
Fix param generation for function pointers
Fixes #10
Diffstat (limited to 'src/CodeParser')
| -rw-r--r-- | src/CodeParser/CParser.ts | 39 |
1 files changed, 34 insertions, 5 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(); }); |