Sublime Forum

A Snippet, Regex C++ and My Uselessness

#1

This is probably only just an Sublime Text 3 question but after two and half hours I give up trying to do it my self, and ask for help.

I have an ST3 for C++ class. And for the header guards I’d like to turn

myclassfile.hpp into MYCLASSFILE_HPP

ie turning the name of the file into capitals and replacing the “.” with “_”

This “capitalises” and gets rids of any forward slashes:


#ifndef ${1:${TM_FILENAME/(.+)[^/]/\U\/(\w)?[.]_ $1/:name}}
#define ${1:${TM_FILENAME/(.+)[^/]/\U\/(\w)?[.]_ $1/:name}}

This is what I’m currently trying and is failing

#ifndef ${1:${TM_FILENAME/[^/.]/\U\_?[:all]+ $1/:name}}
#define ${1:${TM_FILENAME/[^/.]/\U\_?[:all]+ $1/:name}}

And this is part of the snippet, just so you get an idea of what’s going on. I’ve been working at this on and off for a year, so it’d be nice if I could get this little (ha ha ha ha ha) job sorted ! :crazy_face: :kissing_heart:

<snippet>
	<content><![CDATA[
#ifndef ${1:${TM_FILENAME/[^/.]/\U\_?[:all]+ $1/:name}}
#define ${1:${TM_FILENAME/[^/.]/\U\_?[:all]+ $1/:name}}

 // #define NDEBUG

class ${2:${TM_FILENAME/(.+)\..+|.*/$1/:name}}
{
	public:
		${2/(\w+).*/$1/}($3)
		{}
		~${2/(\w+).*/$1/}()
		{}

	  ${2/(\w+).*/$1/}(${2/(\w+).*/$1/} const& other) = default;
  	${2/(\w+).*/$1/}& operator=(${2/(\w+).*/$1/} const& rhs)

		${2/(\w+).*/$1/}(${2/(\w+).*/$1/}&& other)
		{
			std::cout<<"move";
		}

		${2/(\w+).*/$1/}& operator=(${2/(\w+).*/$1/}&& other)
		{

I’m sure I’m not a million miles away, but there’s only so much failure at the start of the day I can put up with :sob:

Muchisimos gracias

:unicorn: :skull_and_crossbones:

0 Likes

#2

Maybe

<snippet>
    <content><![CDATA[
#ifndef ${1:__${TM_FILENAME/(.+)\.([^\.]+)/\U$1_$2/g}__}
#define ${1:__${TM_FILENAME/(.+)\.([^\.]+)/\U$1_$2/g}__}

class ${2:${TM_FILENAME/(.+)\.[^\.]+/\u$1/}}
{
	public:
		${2/(\w+).*/$1/}($3)
		{}
		~${2/(\w+).*/$1/}()
		{}

		${2/(\w+).*/$1/}(${2/(\w+).*/$1/} const& other) = default;
		${2/(\w+).*/$1/}& operator=(${2/(\w+).*/$1/} const& rhs);

		${2/(\w+).*/$1/}(${2/(\w+).*/$1/}&& other)
		{
			std::cout<<"move";
		}

		${2/(\w+).*/$1/}& operator=(${2/(\w+).*/$1/}&& other)
		{
		}
}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <tabTrigger>ifdef</tabTrigger>
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.c++</scope>
</snippet>
1 Like

#3

@deathaxe, thank you very much ! Wicked; wasn’t too far off but as everyone knows a few misplaced characters and all hell can break loose. (Not that I’d have it any other way)

Thanks again.

0 Likes