Home Download Buy Blog Forum Support

Regex snippet question

Re: Regex snippet question

Postby coderascal on Fri Jun 14, 2013 2:25 am

This was very helpful! I was looking for a way to automatically generate the cHeader file #ifndef / #ifdef stuff using the filename and starting with the info above I was able to end up with

Code: Select all
#ifndef INCLUDED_${TM_FILENAME/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}
#define INCLUDED_${TM_FILENAME/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}

#endif


which, if the filename is myfile.h gives
Code: Select all
#ifndef INCLUDED_MYFILE_H
#define INCLUDED_MYFILE_H

#endif


Then I went crazy and created this snippet
Code: Select all
<snippet>
<!--
$1 == package
$2 == class
$3 == constructor arguments
$10 == decide if purpose/example exists. backspace if you don't want it
$11 == purpose
$12 == decide if example exists. backspace if you don't want it.
$13 == example

$0 == end point == class parameters
-->
    <content>
<![CDATA[
// package $1
// $TM_FILENAME

#ifndef INCLUDED_${1/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}_${TM_FILENAME/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}
#define INCLUDED_${1/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}_${TM_FILENAME/([a-zA-Z]+)(?:(\.+?)|\b)/?1:\U$1(?2:_)\E/g}

#include <string>

namespace coderascal \{
namespace ${1:package} \{

// Class: ${2:${TM_FILENAME/([a-zA-Z]+)(?:(\.t?)|\b).h/?1:\u$1(?2:_T)/g}}
// Author: Dennis Gove (coderascal)
${10://
// Purpose:
//  ${11:Don't forget to fill in your purpose for class $2}
${12://
// Example:
//  ${13:Examples are really (really) (super really) helpful. Come on. Do it.}}
}

class $2 \{
   
public:
    $2($0);
    $2(const $2& orig);
    ~$2();

private:

\} // end class

\} // namespace $1
\} // namespace coderascal

#endif
]]>
    </content>
    <tabTrigger>newh</tabTrigger> -->
</snippet>
coderascal
 
Posts: 1
Joined: Fri Jun 14, 2013 1:40 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 8 guests