File: langfilter.rb

package info (click to toggle)
docdiff 0.5.0%2Bgit20160313-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 896 kB
  • ctags: 722
  • sloc: ruby: 14,138; makefile: 98; lisp: 33; sh: 26
file content (14 lines) | stat: -rw-r--r-- 398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/ruby
# language filter
# usage: langfilter.rb --en <infile >outfile

def ruby_m17n?
  return true if "".respond_to? :encoding
end

lang_to_include = ARGV.shift.gsub(/-+/, "")
lang_to_exclude = {"en"=>"ja", "ja"=>"en"}[lang_to_include]
re = /<([a-z]+) +(?:(?:lang|title)="#{lang_to_exclude}").*?>.*?<\/\1>[\r\n]?/m

ARGF.set_encoding("UTF-8") if ruby_m17n?
ARGF.read.gsub(re, "").display