Skip to content

Instantly share code, notes, and snippets.

@71
Created October 16, 2023 14:08
Show Gist options
  • Save 71/557b4aa0dbda88e6f8eadfb96cdba4ab to your computer and use it in GitHub Desktop.
Save 71/557b4aa0dbda88e6f8eadfb96cdba4ab to your computer and use it in GitHub Desktop.
C++ include guard VS Code snippet: replace special characters with _, make upper case
{
"New C++ header": {
"prefix": "newh",
"body": [
// VS Code snippets do not support recursive replacements so we must be
// creative: replace segments like `foo/`, `bar.` and `h<eos>` to `FOO_`,
// `BAR_` and `H_` such that `foo/bar.h` becomes `FOO_BAR_H_`.
"#ifndef PROJECT_${RELATIVE_FILEPATH/(\\w+)(?:\\.|\\/|$)/${1:/upcase}_/g}",
"#define PROJECT_${RELATIVE_FILEPATH/(\\w+)(?:\\.|\\/|$)/${1:/upcase}_/g}",
"",
"namespace project {",
"",
"$0",
"",
"} // namespace project",
"",
"#endif // PROJECT_${RELATIVE_FILEPATH/(\\w+)(?:\\.|\\/|$)/${1:/upcase}_/g}"
],
"isFileTemplate": true,
"scope": "cpp",
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment