Author Topic: Capturing text from a regexp in a macro  (Read 4914 times)

foufee

  • Junior Community Member
  • Posts: 2
  • Hero Points: 0
Capturing text from a regexp in a macro
« on: August 05, 2008, 10:52:10 PM »
Hi,
  This is probably pretty simple, but currently having a bit of difficulty getting started.  What I want to do is search the current file for
"CPPUNIT_TEST_SUITE.*\((.*)," and extract the capture, and then invoke a tool using the capture as an argument.

  Can it be done, and can anyone give me a push in the right direction?

  Cheers

  Matthew

hs2

  • Senior Community Member
  • Posts: 2762
  • Hero Points: 292
Re: Capturing text from a regexp in a macro
« Reply #1 on: August 06, 2008, 02:31:13 AM »
Hi foufee, this example (ripped from my macro toolbox) could help:
(Note: <EXPR> and <TOOL> is pseudo code.)
Code: [Select]
   ...
   // that's the key: _select_match() converts a hilited search hit to a selection
   if ( !search(<EXPR>, "<R" ) ) _select_match();

   if ( select_active2 () )
   {
      _str  cur_sel_word = '';
      int   first_col, last_col, buf_id, junk;
      /* get text out of selection */
      _get_selinfo( first_col, last_col, buf_id );

      if ( _select_type ()=='LINE' )
         get_line( cur_sel_word );
      else
         cur_sel_word=_expand_tabsc( first_col,last_col-first_col );

      _str cmdline = <TOOL> :+ " " :+ cur_sel_word;
      shell (cmdline,"AP");

      // or in the build window
      // activate_build ();
      // concur_command (cmdline, true, true, false, false);
   }
   ...

Have fun, HS2