Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use utf8;
- binmode STDOUT,":utf8";
- use File::Find;
- my $checkre = qr/(?|
- (\()(?&matched)([\}\]”›»】〉》」』]|$) |
- (\{)(?&matched)([\)\]”›»】〉》」』]|$) |
- (\[)(?&matched)([\)\}”›»】〉》」』]|$) |
- (“)(?&matched)([\)\}\]›»】〉》」』]|$) |
- (‹)(?&matched)([\)\}\]”»】〉》」』]|$) |
- («)(?&matched)([\)\}\]”›】〉》」』]|$) |
- (【)(?&matched)([\)\}\]”›»〉》」』]|$) |
- (〈)(?&matched)([\)\}\]”›»】》」』]|$) |
- (《)(?&matched)([\)\}\]”›»】〉」』]|$) |
- (「)(?&matched)([\)\}\]”›»】〉》』]|$) |
- (『)(?&matched)([\)\}\]”›»】〉》」]|$) |
- (^)(?&matched)([\)\}\]”›»】〉》」』]))
- (?(DEFINE)(?<matched>(?:
- \((?&matched)\) |
- \{(?&matched)\} |
- \[(?&matched)\] |
- “(?&matched)” |
- ‹(?&matched)› |
- «(?&matched)» |
- 【(?&matched)】 |
- 〈(?&matched)〉 |
- 《(?&matched)》 |
- 「(?&matched)」 |
- 『(?&matched)』 |
- [^\(\{\[“‹«【〈《「『\)\}\]”›»】〉》」』]++)*+))
- /sx;
- sub check_file {
- if(-f && /\.txt$/) {
- if(open(my $fh,'<:encoding(UTF-8)',$_)) {
- undef $/;
- my $data = <$fh>;
- if($data =~ $checkre) {
- if(!length $2) {
- print "File $File::Find::name has unclosed bracket $1 at position $-[1]\n";
- }
- elsif(!length $1) {
- print "File $File::Find::name has unopened bracket $2 at position $-[2]\n";
- }
- else {
- print "File $File::Find::name has mismatched brackets $1 $2 at positions $-[1] and $-[2]\n";
- }
- }
- } else {
- print STDERR "Cannot open $File::Find::name: $!\n";
- }
- }
- }
- @ARGV = ('.') unless @ARGV;
- find(\&check_file,@ARGV);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement