Module: GritExt
Instance Method Summary collapse
Instance Method Details
#clean(message) ⇒ Object
35 36 37 38 39 |
# File 'lib/grit_ext.rb', line 35 def clean() .encode("UTF-16BE", :undef => :replace, :invalid => :replace, :replace => "") .encode("UTF-8") .gsub("\0".encode("UTF-8"), "") end |
#encode!(message) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/grit_ext.rb', line 12 def encode!() return nil unless .respond_to? :force_encoding # if message is utf-8 encoding, just return it .force_encoding("UTF-8") return if .valid_encoding? # return message if message type is binary detect = CharlockHolmes::EncodingDetector.detect() return .force_encoding("BINARY") if detect && detect[:type] == :binary # encoding message to detect encoding if detect && detect[:encoding] .force_encoding(detect[:encoding]) end # encode and clean the bad chars .replace clean() rescue encoding = detect ? detect[:encoding] : "unknown" "--broken encoding: #{encoding}" end |
#version ⇒ Object
4 5 6 |
# File 'lib/grit_ext/version.rb', line 4 def version "0.8.1" end |