loic.k
loic.k

Reputation: 83

Upper case file code templates CLion

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_

Upvotes: 0

Views: 1209

Answers (1)

user9305149
user9305149

Reputation:

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

Upvotes: 1

Related Questions