当我创建一个文件时,如何将我的文件名变量${NAME}放入文件和代码模板部分中? 我发现的唯一方法是在文件中按组合cmd + shift + U,但当我有很多时候,它需要相当多的时间! 例如,当我创建一个test.hpp文件时,我希望在其中包含#ifndef TEST_HPP_ ,这里是我现在的模板: #[[#ifndef]]# ${NAME}_HPP_
How to put my filename variable ${NAME} in the file and code template section into upper case when I create a file ? The only way i found is to press the combination cmd + shift + U in the files but when I have a lot of then it takes pretty much time ! For exemple when i create a test.hpp file, I want to have #ifndef TEST_HPP_ in it, here is my template for now : #[[#ifndef]]# ${NAME}_HPP_
最满意答案
如果您转到Jetbrains网站上的文件和代码模板帮助( https://www.jetbrains.com/help/clion/file-and-code-templates.html )。
文件和代码模板是用速度模板语言(VTL)编写的,
...
使用#set VTL指令创建自定义模板变量并在include模板中定义它们的值。 例如,要将全名插入文件头中而不是通过$ {USER}变量定义的登录名,请编写以下结构:
#set( $MyName = "John Smith" )
这意味着您可以使用此语法将字符串置于大写。
下面是你的问题的例子(来自速度字符串函数 ):
#set($nameUpper = ${NAME}) #set($nameUpper = $nameUpper.substring(0).toUpperCase())然后,你可以使用你的新变量为你的ifndef。
#[[#ifndef]]# ${nameUpper}_HPP_ #[[#define]]# ${nameUpper}_HPP_ #[[#endif]]# //${nameUpper}_HPP_Woking在CLion 2017.3.3上
If you go to File and Code Templates Help on Jetbrains website (https://www.jetbrains.com/help/clion/file-and-code-templates.html).
File and code templates are written in the Velocity Template Language (VTL)
...
Create custom template variables and define their values right in the include template using the #set VTL directive. For example, to insert your full name in the file header instead of your login name defined through the ${USER} variable, write the following construct:
#set( $MyName = "John Smith" )
Meaning that you can use this syntax for putting your string in uppercase.
Here is an example for your problem (from Velocity string function):
#set($nameUpper = ${NAME}) #set($nameUpper = $nameUpper.substring(0).toUpperCase())Then, you can then use your new variable for your ifndef.
#[[#ifndef]]# ${nameUpper}_HPP_ #[[#define]]# ${nameUpper}_HPP_ #[[#endif]]# //${nameUpper}_HPP_Woking on CLion 2017.3.3
更多推荐
发布评论