I have a line:
int INTVAR;
I would like to highlight this line, and run a snippet which automatically creates the following set of three lines in place of the single line above.
int INTVAR;
int intvar() {return INTVAR;}
void intvar(int val){INTVAR = val;}
That is, a function that it a getter/setter for the variable should automatically be generated. The variable name will always be in full capital letters. The getter/setter name should be the same except that they will always be in lower case.
int
could also be a double
, char
, etc.
ETA:
What I have tried/know so far: Instead of highlighting the line, the following appears more straightforward where I just type the declaration once and the getters/setters are automatically added.
"int var set get":{
"prefix": "intsetget",
"body":[
"int ${1:VARNM};",
"int ${1:/downcase}(){return ${1};}",
"void ${1:/downcase}(int val){${1} = val;}"
]
}
This almost gets the job done, except that the downcase for setter and getter name does not work.
f
orm_
, I have edited the snippet