Sha256: c71d1c78344735761a7e1ccfa0c68f767480e296a06ed0257bde6a885a87b0db

Contents?: true

Size: 647 Bytes

Versions: 7

Compression:

Stored size: 647 Bytes

Contents

#!/usr/bin/env ruby
# encoding:UTF-8

if ARGV.include?('--help')
  puts <<USAGE
wu-clean-encoding cleans malformed characters from stdin.

If a character is malformed, as defined by valid_encoding?,
it is replaced with a '�'.

wu-clean-encoding was built to work with UTF-8, and no 
guarantees are provided for other encodings.
USAGE
  exit(0)
end

ARGF.each do |line|
  if line.valid_encoding?
    $stdout.write line
  else 
    repaired_line = []
    line.each_char do |char|
      if char.valid_encoding?
        repaired_line << char
      else
        repaired_line << "�"
      end
    end
    $stdout.write repaired_line.join
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ul-wukong-4.1.1 bin/wu-clean-encoding
ul-wukong-4.1.0 bin/wu-clean-encoding
wukong-4.0.0 bin/wu-clean-encoding
wukong-3.0.1 bin/wu-clean-encoding
wukong-3.0.0 bin/wu-clean-encoding
wukong-3.0.0.pre3 bin/wu-clean-encoding
wukong-3.0.0.pre2 bin/wu-clean-encoding