This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push:
new ca6ff093 Add verbose (-v) option
ca6ff093 is described below
commit ca6ff093d6d248dcec4c8a0ab57218809efce45c
Author: Sebb <[email protected]>
AuthorDate: Sat Aug 12 13:58:28 2023 +0100
Add verbose (-v) option
---
lib/whimsy/utf8-utils.rb | 7 ++++++-
tools/utf8-fix.rb | 8 ++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/lib/whimsy/utf8-utils.rb b/lib/whimsy/utf8-utils.rb
index 990d6974..05303057 100755
--- a/lib/whimsy/utf8-utils.rb
+++ b/lib/whimsy/utf8-utils.rb
@@ -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)
@@ -21,6 +21,11 @@ module UTF8Utils
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
diff --git a/tools/utf8-fix.rb b/tools/utf8-fix.rb
index 44cb455a..5c5e9c47 100755
--- a/tools/utf8-fix.rb
+++ b/tools/utf8-fix.rb
@@ -6,8 +6,12 @@ $LOAD_PATH.unshift '/srv/whimsy/lib'
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