I tried to create a snippet in VSCode to quickly include C++ header guards. For example with a file path is C:\workspace\src\chrome\browser\ui\webui\settings\about_handler.h
The snippet is expected to generate like this:
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_
From VScode snippet syntax guide, I tried to use TM_FILEPATH
variable but cannot find a solution to transform the filepath into the macros above. I tried some way below:
- with the transform
${TM_FILEPATH/([^a-zA-Z0-9])|([a-zA-Z0-9])/${1:+_}${2:/upcase}/g}_
I can generate the filepath intoC__WORKSPACE_SRC_CHROME_BROWSER_UI_WEBUI_SETTINGS_ABOUT_HANDLER_H_
. This regex will convert all non-digit and non-alphabetic characters to_
and change all alphabetic characters to upper case. - with the transform
${TM_FILEPATH/.*src[\\\\\\/](.*)/${1:/upcase}/}
I can generate intoCHROME\BROWSER\UI\WEBUI\SETTINGS\ABOUT_HANDLER.H
. This regex remove the path from begining tosrc
since my current workspace is insrc
folder so I want my header macro to be related to that.
The problem is I cannot combine these two transform to get the macro I want. Is there any ideas to make it works?