diff --git a/package.json b/package.json index 1bb5277..f458a64 100755 --- a/package.json +++ b/package.json @@ -66,23 +66,23 @@ "type": "string", "editPresentation": "multilineText", "default": "#ifndef {{*CLASSNAMEUPPER*}}_H\n#define {{*CLASSNAMEUPPER*}}_H\n\n#pragma once\n\nclass {{*CLASSNAME*}}\n{\npublic:\n {{*CLASSNAME*}}();\n ~{{*CLASSNAME*}}();\n\nprivate:\n\n};\n\n#endif", - "description": "Content of your created header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time." + "description": "Content of your created header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*CLASSNAMESNAKE*}} - entered CamelCase classname in snake_case.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time." }, "cpp.creator.sourceFileContentPreset": { "type": "string", "editPresentation": "multilineText", "default": "#include \"{{*HEADERFILENAME*}}\"\n\n{{*CLASSNAME*}}::{{*CLASSNAME*}}()\n{\n\n}\n\n{{*CLASSNAME*}}::~{{*CLASSNAME*}}()\n{\n\n}", - "description": "Content of your created source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time." + "description": "Content of your created source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMECAPI*}} - default classname with capitalized first letter.\n{{*CLASSNAMESNAKE*}} - entered CamelCase classname in snake_case.\n{{*HEADERFILENAME*}} - default headerfilename as entered in the settings. \n{{*SOURCEFILENAME*}} - default sourcefilename as entered in the settings.\n{{*CURRENTDATETIME*}} - current date and time.\n{{*CURRENTDATE*}} - current date.\n{{*CURRENTTIME*}} - current time." }, "cpp.creator.sourceFileNamePreset": { "type": "string", "default": "{{*CLASSNAME*}}.cpp", - "description": "Name of your source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters." + "description": "Name of your source file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMESNAKE*}} - entered CamelCase classname in snake_case." }, "cpp.creator.headerFileNamePreset": { "type": "string", "default": "{{*CLASSNAME*}}.h", - "description": "Name of your header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters." + "description": "Name of your header file. \nAvailable commands are:\n{{*CLASSNAME*}} - entered classname.\n{{*CLASSNAMEUPPER*}} - entered classname in upper-case letters.\n{{*CLASSNAMELOWER*}} - entered classname in lower-case letters.\n{{*CLASSNAMESNAKE*}} - entered CamelCase classname in snake_case." }, "cpp.creator.createFolder": { "type": "boolean", diff --git a/src/class_creator.ts b/src/class_creator.ts index f09352e..ac21c49 100644 --- a/src/class_creator.ts +++ b/src/class_creator.ts @@ -31,6 +31,7 @@ export class class_creator var upper_regex : RegExp = /{{\*CLASSNAMEUPPER\*}}/gi; var lower_regex : RegExp = /{{\*CLASSNAMELOWER\*}}/gi; var cap_regex : RegExp = /{{\*CLASSNAMECAPI\*}}/gi; + var snake_case_regex : RegExp = /{{\*CLASSNAMESNAKE\*}}/gi; var default_regex : RegExp = /{{\*CLASSNAME\*}}/gi; var headerfilename_regex : RegExp = /{{\*HEADERFILENAME\*}}/gi; var sourcefilename_regex : RegExp = /{{\*SOURCEFILENAME\*}}/gi; @@ -42,6 +43,7 @@ export class class_creator { reg_expression: upper_regex, replace_string: regex_commands.upper_case(this.class_name)},// CLASSNAMEUPPER - default classname to upper { reg_expression: lower_regex, replace_string: regex_commands.lower_case(this.class_name)},// CLASSNAMELOWER - default classname to lower { reg_expression: cap_regex, replace_string: regex_commands.capitalize(this.class_name)}, // CLASSNAMECAPI - default classname with capitalized first letter + { reg_expression: snake_case_regex, replace_string: regex_commands.to_snake_case(this.class_name)}, // CLASSNAMESNAKE - default CamelCase classname in snake_case { reg_expression: default_regex, replace_string: regex_commands.default(this.class_name)}, // CLASSNAME - default classname ] @@ -51,6 +53,7 @@ export class class_creator { reg_expression: upper_regex, replace_string: regex_commands.upper_case(this.class_name)}, // CLASSNAMEUPPER - default classname to upper { reg_expression: lower_regex, replace_string: regex_commands.lower_case(this.class_name)}, // CLASSNAMELOWER - default classname to lower { reg_expression: cap_regex, replace_string: regex_commands.capitalize(this.class_name)}, // CLASSNAMECAPI - default classname with capitalized first letter + { reg_expression: snake_case_regex, replace_string: regex_commands.to_snake_case(this.class_name)}, // CLASSNAMESNAKE - default CamelCase classname in snake_case { reg_expression: default_regex, replace_string: regex_commands.default(this.class_name)}, // CLASSNAME - default classname { reg_expression: datetime_regex, replace_string: regex_commands.current_date_time()}, // CURRENTDATETIME - the current date and time { reg_expression: date_regex, replace_string: regex_commands.current_date()}, // CURRENTDATE - the current date @@ -117,4 +120,4 @@ export class class_creator return (hpp && cpp); } -} \ No newline at end of file +} diff --git a/src/regex_commands.ts b/src/regex_commands.ts index b219a2c..6bc30ad 100644 --- a/src/regex_commands.ts +++ b/src/regex_commands.ts @@ -15,6 +15,11 @@ export abstract class regex_commands return str.toUpperCase(); } + public static to_snake_case(str: string) + { + return str.replace(/([a-z])([A-Z0-9])/g, '$1_$2').toLowerCase(); + } + public static capitalize(str: string) : string { return str[0].toUpperCase() + str.substring(1); @@ -47,4 +52,4 @@ export abstract class regex_commands let dateTime = new Date(); return dateTime.toLocaleString(); } -} \ No newline at end of file +}