From db61002b0d4bdf58bf8798ad7956ee9c64d29a2b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 5 Dec 2012 02:34:15 +0100 Subject: [PATCH] Small improvements. --- lib/encode.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/encode.rb b/lib/encode.rb index 9daf07bd1..c6cb5f7c5 100644 --- a/lib/encode.rb +++ b/lib/encode.rb @@ -1,15 +1,15 @@ #require 'iconv' -class Encode +module Encode def self.conv (charset, string) + # return if string is false + return string if !string + # if no charset is given, use LATIN1 as default if !charset || charset == 'US-ASCII' || charset == 'ASCII-8BIT' charset = 'LATIN1' end - # return if string is false - return string if !string - # validate already existing utf8 strings if charset.downcase == 'utf8' || charset.downcase == 'utf-8' begin @@ -22,10 +22,16 @@ class Encode string.encode!( 'UTF-8', 'Windows-1252' ) rescue EncodingError => e - puts "Bad encoding: #{new_value.inspect}" + puts "Bad encoding: #{string.inspect}" string.encode!( 'UTF-8', invalid: :replace, undef: :replace, replace: '?' ) end return string end + +# puts '-------' + charset +# puts string + # convert string + string.encode!( 'UTF-8', charset.upcase ) +# Iconv.conv( 'UTF8', charset, string ) end end \ No newline at end of file