diff options
| author | Christoph Schlosser <christoph@linux.com> | 2018-03-02 17:02:02 +0100 |
|---|---|---|
| committer | Christoph Schlosser <christophschlosser@users.noreply.github.com> | 2018-03-02 20:24:28 +0100 |
| commit | f062b00a6ca2a5f42eb376b178735b766832bbcb (patch) | |
| tree | 2879fb8b19e8b6573a680498ab9cfe3d4edb7af5 /src/Lang/Cpp/CppDocGen.ts | |
| parent | 5368c8151df632ba0ebd863cbc7ff105dc4027bf (diff) | |
| download | doxdocgen-f062b00a6ca2a5f42eb376b178735b766832bbcb.tar.gz | |
Add more smart text
- Getter
- Setter
- Factory method
Diffstat (limited to 'src/Lang/Cpp/CppDocGen.ts')
| -rw-r--r-- | src/Lang/Cpp/CppDocGen.ts | 88 |
1 files changed, 77 insertions, 11 deletions
diff --git a/src/Lang/Cpp/CppDocGen.ts b/src/Lang/Cpp/CppDocGen.ts index eb60c9a..d93c858 100644 --- a/src/Lang/Cpp/CppDocGen.ts +++ b/src/Lang/Cpp/CppDocGen.ts @@ -10,6 +10,9 @@ export enum SpecialCase { none, constructor, destructor, + getter, + setter, + factoryMethod, } export enum CommentType { @@ -17,6 +20,15 @@ export enum CommentType { file, } +export enum CasingType { + Pascal, + camel, + snake, + SCREAMING_SNAKE, + UPPER, + uncertain, +} + export class CppDocGen implements IDocGen { protected activeEditor: TextEditor; @@ -28,6 +40,7 @@ export class CppDocGen implements IDocGen { protected specialCase: SpecialCase; protected commentType: CommentType; + protected casingType: CasingType; protected smartTextLength: number; @@ -48,6 +61,7 @@ export class CppDocGen implements IDocGen { params: CppArgument[], specialCase: SpecialCase, commentType: CommentType, + casingType: CasingType, ) { this.activeEditor = actEdit; this.cfg = cfg; @@ -57,6 +71,7 @@ export class CppDocGen implements IDocGen { this.specialCase = specialCase; this.commentType = commentType; this.smartTextLength = 0; + this.casingType = casingType; } /** @@ -93,35 +108,52 @@ export class CppDocGen implements IDocGen { if (!this.cfg.Generic.generateSmartText) { return ""; } + let val: string = ""; + let text: string = ""; switch (this.specialCase) { case SpecialCase.constructor: { if (this.func.name === null) { return ""; } else { - const str = this.getTemplatedString(this.cfg.nameTemplateReplace, - this.cfg.Cpp.ctorText, - this.func.name.trim()); - this.smartTextLength = str.length; - return str; + val = this.splitCasing(this.func.name.trim()); + text = this.cfg.Cpp.ctorText; + break; } } case SpecialCase.destructor: { if (this.func.name === null) { return ""; } else { - const str = this.getTemplatedString(this.cfg.nameTemplateReplace, - this.cfg.Cpp.dtorText, - this.func.name.replace("~", "").trim()); - this.smartTextLength = str.length; - return str; + val = this.splitCasing(this.func.name.replace("~", "").trim()); + text = this.cfg.Cpp.dtorText; + break; } } - // tslint:disable-next-line:no-empty + case SpecialCase.getter: { + val = this.splitCasing(this.func.name.trim()).trim().substr(3).trim(); + text = this.cfg.C.getterText; + break; + } + case SpecialCase.setter: { + val = this.splitCasing(this.func.name.trim()).trim().substr(3).trim(); + text = this.cfg.C.setterText; + break; + } + case SpecialCase.factoryMethod: { + val = this.splitCasing(this.func.name.trim()).trim().substr(6).trim(); + text = this.cfg.C.factoryMethodText; + break; + } case SpecialCase.none: default: { return ""; } } + const str = this.getTemplatedString(this.cfg.nameTemplateReplace, + text, + val); + this.smartTextLength = str.length; + return str; } protected generateBrief(lines: string[]) { @@ -317,4 +349,38 @@ export class CppDocGen implements IDocGen { const to: Position = new Position(line, character); this.activeEditor.selection = new Selection(from, to); } + + protected splitCasing(text: string): string { + if (!this.cfg.Generic.splitCasingSmartText) { + return text; + } + let txt = text; + let vals: string[] = []; + switch (this.casingType) { + case CasingType.SCREAMING_SNAKE: { + txt = txt.toLowerCase(); + } + case CasingType.snake: { + vals = txt.split("_"); + break; + } + case CasingType.Pascal: { + txt = txt.replace(/([A-Z0-9])/g, " $1"); + vals.push(txt); + break; + } + case CasingType.camel: { + txt = txt.replace(/([a-zA-Z0-9])(?=[A-Z])/g, "$1 "); + vals.push(txt); + break; + } + case CasingType.UPPER: + case CasingType.uncertain: + default: { + return text; + } + } + + return vals.join(" "); + } } |