Created
July 17, 2011 13:19
-
-
Save rklemme/1087583 to your computer and use it in GitHub Desktop.
Find files with non balanced brackets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby19 | |
# -*- coding: utf-8 -*- | |
require 'find' | |
ARGV.each do |dir| | |
Find.find dir do |f| | |
next unless test ?f, f | |
content = File.read(f, :encoding => 'UTF-8') | |
md = %r{ | |
\A | |
(?<tl> | |
[^(){}\[\]“”‹›«»【】〈〉《》「」『』]++ | |
| \( \g<tl>* \) | |
| \{ \g<tl>* \} | |
| \[ \g<tl>* \] | |
| “ \g<tl>* ” | |
| ‹ \g<tl>* › | |
| « \g<tl>* » | |
| 【 \g<tl>* 】 | |
| 〈 \g<tl>* 〉 | |
| 《 \g<tl>* 》 | |
| 「 \g<tl>* 」 | |
| 『 \g<tl>* 』 | |
)* | |
}x.match content | |
len = md[0].length | |
printf "file %s, pos %d\n", f, len if len < content.length | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment