-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVeryKiwiRegex.pm
40 lines (33 loc) · 974 Bytes
/
VeryKiwiRegex.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package VeryKiwiRegex;
use strict; use warnings;
use VeryKiwiHelpers;
use VeryKiwiMorpher; our @ISA = 'VeryKiwiMorpher';
################################ GLOBALS FOR ALL REGEXS ################################
our $r = qr/sq?|mq?/;
######################################## REGEX #########################################
sub new{
my $regex = VeryKiwiMorpher::new( @_ );
unless( $regex->prefix =~ m/^$r$/ ){ die 'Non-regex prefix.' }
return $regex
}
sub is_quoted{
my $regex = shift;
return $regex->prefix =~ m/q$/
}
sub opts{
my $regex = shift;
return ($regex->is_quoted)? qr/(?:g?m?o?p?i?)*/: qr/(?:g?m?o?p?i?s?x?e?)*/;
}
sub mind_the_delim{ # takes any strings and escapes all occurances of $delim
my $regex = shift;
my @strings = @_;
if( $regex->is_quoted ){
my $delim = $regex->delim('Q');
foreach my $string (@strings){ $string =~ s/$delim//g } # delete the delim
}
else{
@strings = $regex->escape_the_delim(@strings);
}
return @strings
}
1