Browse Source

- improved regex a little bit using look-behind

- improved regex a little bit using look-ahead
- avoiding shift
master
parent
commit
034f160f99
1 changed files with 8 additions and 10 deletions
  1. +8
    -10
      lib/File/FormatIdentification/Regex.pm

+ 8
- 10
lib/File/FormatIdentification/Regex.pm View File

@@ -53,19 +53,18 @@ sub or_combine (@) {
}

sub simplify_two_or_combined_regex($$) {
my $rx1 = shift;
my $rx2 = shift;
my $rx1 = $_[0];
my $rx2 = $_[1];
my $common = "";
my $rx = qr#\(([A-Za-z0-9]*)\)#;
if (
# ($rx1 =~ m#\(([A-Za-z0-9]*)|(\\x[0-9A-F]{2})*\)#) &&
# ($rx2 =~ m#\(([A-Za-z0-9]*)|(\\x[0-9A-F]{2})*\)#)
( $rx1 =~ m#\(([A-Za-z0-9]*)\)# )
&& ( $rx2 =~ m#\(([A-Za-z0-9]*)\)# )

( $rx1 =~ m/$rx/ ) and ( $rx2 =~ m/$rx/ )
)
{
# only left simplify supported yet
my $common = String::LCSS::lcss( $rx1, $rx2 );
$common = String::LCSS::lcss( $rx1, $rx2 );

#say "";
#say "Found common='$common' of rx1='$rx1' rx2='$rx2'";
@@ -76,19 +75,18 @@ sub simplify_two_or_combined_regex($$) {

sub hex_replace_to_bracket {
my $regex = shift;
$regex =~ s#\\x([0-9A-F]{2})#\\x{$1}#g;
$regex =~ s#(?<=\\x)([0-9A-F]{2})#{$1}#g;
return $regex;
}

sub hex_replace_from_bracket {
my $regex = shift;
$regex =~ s#\\x\{([0-9A-F]{2})\}#\\x$1#g;
$regex =~ s#(?<=\\x)\{([0-9A-F]{2})\}#$1#g;
return $regex;
}

sub peep_hole_optimizer ($) {
my $regex = shift
; # only works if special Regexes within File::FormatIdentification:: used
my $regex = $_[0]; # only works if special Regexes within File::FormatIdentification:: used
$regex = hex_replace_to_bracket($regex);
my $oldregex = $regex;
##### first optimize bracket-groups


Loading…
Cancel
Save