Changeset 24829 for main/trunk/greenstone2/perllib/util.pm
- Timestamp:
- 2011-11-30T17:48:15+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/util.pm
r24563 r24829 839 839 # need to put single backslash back to double so that regex works 840 840 if ($ENV{'GSDLOS'} =~ /^windows$/i) { 841 $filename =~ s/\\/\\\\/g; 842 } 841 $filename =~ s/\\/\\\\/g; 842 } 843 844 # note that the first part of a substitution is a regex, so RE chars need to be escaped, 845 # the second part of a substitution is not a regex, so for e.g. full-stop can be specified literally 846 $filename =~ s/\./\\./g; # in case there are extensions/other full stops, escape them 847 $filename =~ s@\(@\\(@g; # escape brackets 848 $filename =~ s@\)@\\)@g; # escape brackets 849 850 return $filename; 851 } 852 853 sub unregex_filename { 854 my $filename = shift (@_); 855 856 # need to put doubled backslashes for regex back to single 857 $filename =~ s/\\\\/\\/g; # remove RE syntax for \ 858 $filename =~ s/\\\./\./g; # remove RE syntax for . 859 $filename =~ s@\\\(@(@g; # remove RE syntax for ( => "\(" turns into "(" 860 $filename =~ s@\\\)@)@g; # remove RE syntax for ) => "\)" turns into ")" 843 861 return $filename; 844 862 } … … 928 946 if ($ENV{'GSDLOS'} =~ /^windows$/i) 929 947 { 930 my $escaped_val = $val; 931 $escaped_val =~ s/\\/\\\\/g; # escape any Windows backslashes for upcoming regex 948 my $escaped_val = &filename_to_regex($val); # escape any Windows backslashes and brackets for upcoming regex 932 949 if (!defined($ENV{$var})) { 933 950 $ENV{$var} = "$val"; … … 953 970 if ($ENV{'GSDLOS'} =~ /^windows$/i) 954 971 { 955 my $escaped_val = $val; 956 $escaped_val =~ s/\\/\\\\/g; # escape any Windows backslashes for upcoming regex 972 my $escaped_val = &filename_to_regex($val); # escape any Windows backslashes and brackets for upcoming regex 957 973 if (!defined($ENV{$var})) { 958 974 $ENV{$var} = "$val"; … … 1048 1064 } 1049 1065 1050 $within_dir =~ s/\\/\\\\/g; # escape DOS style file separator 1051 1066 $within_dir = &filename_to_regex($within_dir); # escape DOS style file separator and brackets 1052 1067 if ($filename =~ m/^$within_dir(.*)$/) { 1053 1068 $filename = $1;
Note:
See TracChangeset
for help on using the changeset viewer.