大写文件代码模板 CLion

Upper case file code templates CLion

如何在创建文件时将文件和代码模板部分中的文件名变量 ${NAME} 变为大写? 我发现的唯一方法是在文件中按组合 cmd + shift + U 但是当我有很多时它会花费很多时间! 例如,当我创建一个 test.hpp 文件时,我想在其中包含 #ifndef TEST_HPP_,这是我现在的模板:#[[#ifndef]]# ${NAME}_HPP_

如果您转到 Jetbrains 网站上的文件和代码模板帮助 (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" )

这意味着您可以使用此语法将字符串设为大写。

这是您的问题的示例(来自 Velocity string function):

#set($nameUpper = ${NAME})
#set($nameUpper = $nameUpper.substring(0).toUpperCase())

然后,您可以将新变量用于 ifndef。

#[[#ifndef]]# ${nameUpper}_HPP_
#[[#define]]# ${nameUpper}_HPP_

#[[#endif]]# //${nameUpper}_HPP_

在 CLion 2017.3.3 上工作