大写文件代码模板CLion(Upper case file code templates CLion)

编程入门 行业动态 更新时间:2024-10-26 00:18:24
大写文件代码模板CLion(Upper case file code templates CLion)

当我创建一个文件时,如何将我的文件名变量${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

更多推荐

本文发布于:2023-07-17 13:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   代码   文件   CLion   Upper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!