Skip to content

Commit

Permalink
Add verbose (-v) option
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Aug 12, 2023
1 parent ed5a777 commit ca6ff09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/whimsy/utf8-utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module UTF8Utils
#
# Initially assumes the file is in utf8-softbank encoding
# If that does not work, then it tries ISO-8859-1
def self.repair(src, dst)
def self.repair(src, dst, verbose=false)
opts = {undef: :replace, invalid: :replace}
ec1 = Encoding::Converter.new('utf8-softbank', "UTF-8", **opts)
ec2 = Encoding::Converter.new('iso-8859-1', "UTF-8", **opts)
Expand All @@ -21,6 +21,11 @@ def self.repair(src, dst)
if o.include? UTF8_REPLACE # something did not convert
o = ec2.convert(l) # try another encoding
end
if verbose
puts l
puts o
puts ''
end
end
w.write o
end
Expand Down
8 changes: 6 additions & 2 deletions tools/utf8-fix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
require 'whimsy/utf8-utils'

if __FILE__ == $0
verbose = !ARGV.delete('-v').nil?
src = ARGV.shift or raise Exception.new "need input file"
dst = ARGV.shift || src + '.tmp'
puts "Input: #{src} output: #{dst}"
UTF8Utils::repair(src, dst)
puts "Input: #{src} output: #{dst} verbose: #{verbose}"
UTF8Utils::repair(src, dst, verbose)
if verbose
puts "Above are the changed lines. Note that some may appear the same, but the encoding has changed."
end
end

0 comments on commit ca6ff09

Please sign in to comment.