Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created July 17, 2011 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rklemme/1087583 to your computer and use it in GitHub Desktop.
Save rklemme/1087583 to your computer and use it in GitHub Desktop.
Find files with non balanced brackets
#!/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