#!/usr/bin/perl -w
# $Id: bench_regexp_complex,v 1.3 2003/09/19 18:52:26 mrodrigu Exp $
use strict;
use simple_benchmark; # to get memory size

use File::Slurp;

use Getopt::Long;

my( $in_file);
GetOptions( 'in_file=s' =>\$in_file); 
$in_file ||= 'test.xml';

my $xml = read_file( $in_file);

# first expand empty process tags, or it the following regexps become a lot more complex
$xml=~ s{(<process [^>]*) />}{$1></process>}gx;

$xml=~ s{<process \s+ [^>]* action \s* = \s* "delete" [^>]*>.*?</process>}
        {}gx;
$xml=~ s{(<process \s+ [^>]* action \s* = \s* "duplicate" [^>]*>.*?</process>)}
        {$1$1}gx;
$xml=~ s{<process( \s+ [^>]* action \s* = \s* "change_tag" [^>]*>.*?)</process>}
        {<new_tag$1</new_tag>}gx;
$xml=~ s{(<process \s+ [^>]* action \s* = \s* "prefix" [^>]*>)}
        {$1<prefix>prefixed </prefix>}gx;
$xml=~ s{(<process \s+ [^>]*) (action \s* = \s* "add_att" [^>]*>)}
        {$1 new_att="foo" $2}gx;
$xml=~ s{<process \s+ [^>]* action \s* = \s* "erase" [^>]*>(.*?)</process>}
        {$1}gx;
print $xml;
