lib/review/preprocessor.rb in review-0.6.0 vs lib/review/preprocessor.rb in review-0.9.0
- old
+ new
@@ -10,10 +10,11 @@
# For details of the GNU LGPL, see the file "COPYING".
#
require 'review/textutils'
require 'review/exception'
+require 'nkf'
module ReVIEW
module ErrorUtils
@@ -97,15 +98,12 @@
yield line unless /\A\#@/ =~ line
end
end
end
- def initialize(repo)
+ def initialize(repo, param)
@repository = repo
- end
-
- def setParameter(param)
@param = param
end
def process(inf, outf)
init_ErrorUtils inf
@@ -179,15 +177,38 @@
def known_directive?(op)
KNOWN_DIRECTIVES.index(op)
end
+ def convert_outencoding(*s)
+ ine = ""
+ if @param["inencoding"] =~ /^EUC$/i
+ ine = "-E,"
+ elsif @param["inencoding"] =~ /^SJIS$/i
+ ine = "-S,"
+ elsif @param["inencoding"] =~ /^JIS$/i
+ ine = "-J,"
+ elsif @param["inencoding"] =~ /^UTF\-8$/i
+ ine = "-W,"
+ end
+
+ if @param["outencoding"] =~ /^EUC$/i
+ NKF.nkf("#{ine} -e", *s)
+ elsif @param["outencoding"] =~ /^SJIS$/i
+ NKF.nkf("#{ine} -s", *s)
+ elsif @param["outencoding"] =~ /^JIS$/i
+ NKF.nkf("#{ine} -j", *s)
+ else
+ NKF.nkf("#{ine} -w", *s)
+ end
+ end
+
def replace_block(f, directive_line, newlines, with_lineno)
@f.print directive_line
newlines.each do |line|
print_number line.number if with_lineno
- @f.print line.string
+ @f.print convert_outencoding(line.string)
end
skip_list f
end
def print_number(num)
@@ -409,10 +430,23 @@
end
private
def file_descripter(fname)
- @repository[fname] ||= parse_file(fname)
+ return @repository[fname] if @repository[fname]
+
+ @repository[fname] = git?(fname) ? parse_git_blob(fname) : parse_file(fname)
+ end
+
+ def git?(fname)
+ fname =~ /\Agit\|/
+ end
+
+ def parse_git_blob(g_obj)
+ IO.popen('git show ' + g_obj.sub(/\Agit\|/, ''), 'r') do |f|
+ init_ErrorUtils f
+ return _parse_file(f)
+ end
end
def parse_file(fname)
File.open(fname) {|f|
init_ErrorUtils f