Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add classname conversion to snake_case #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/class_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
]

Expand All @@ -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
Expand Down Expand Up @@ -117,4 +120,4 @@ export class class_creator

return (hpp && cpp);
}
}
}
7 changes: 6 additions & 1 deletion src/regex_commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -47,4 +52,4 @@ export abstract class regex_commands
let dateTime = new Date();
return dateTime.toLocaleString();
}
}
}