lib/rabbit/source/base.rb in rabbit-2.0.6 vs lib/rabbit/source/base.rb in rabbit-2.0.7
- old
+ new
@@ -42,12 +42,11 @@
end
if /\Autf-?8\z/i =~ enc
@source.force_encoding(enc) if @source.respond_to?(:force_encoding)
else
- require "iconv"
- @source = Iconv.conv("UTF-8", enc, @source)
+ @source = convert_encoding("UTF-8", enc, @source)
end
end
@source
end
@@ -140,9 +139,18 @@
"UTF-16"
when NKF::UTF32
"UTF-32"
else
"UTF-8"
+ end
+ end
+
+ def convert_encoding(to, from, str)
+ if str.respond_to?(:encode)
+ str.encode(to, from)
+ else
+ require "iconv"
+ Iconv.conv(to, from, str)
end
end
def extract_extension(path)
components = ::File.basename(path).split(/\./)