lib/spreadsheet/encodings.rb in spreadsheet-0.6.5.8 vs lib/spreadsheet/encodings.rb in spreadsheet-0.6.5.9
- old
+ new
@@ -1,35 +1,46 @@
+#!/usr/bin/env ruby
+# encoding: utf-8
+# Spreadsheet::Encoding -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com
+# Spreadsheet::Encoding -- spreadheet -- 03.07.2009 -- hwyss@ywesee.com
+
module Spreadsheet
##
# Methods for Encoding-conversions. You should not need to use any of these.
module Encodings
if RUBY_VERSION >= '1.9'
def client string, internal='UTF-16LE'
+ string = string.dup
string.force_encoding internal
string.encode Spreadsheet.client_encoding
end
def internal string, client=Spreadsheet.client_encoding
+ string = string.dup
string.force_encoding client
string.encode('UTF-16LE').force_encoding('ASCII-8BIT')
end
def utf8 string, client=Spreadsheet.client_encoding
+ string = string.dup
string.force_encoding client
string.encode('UTF-8')
end
else
require 'iconv'
@@iconvs = {}
def client string, internal='UTF-16LE'
+ string = string.dup
key = [Spreadsheet.client_encoding, internal]
iconv = @@iconvs[key] ||= Iconv.new(Spreadsheet.client_encoding, internal)
iconv.iconv string
end
def internal string, client=Spreadsheet.client_encoding
+ string = string.dup
key = ['UTF-16LE', client]
iconv = @@iconvs[key] ||= Iconv.new('UTF-16LE', client)
iconv.iconv string
end
def utf8 string, client=Spreadsheet.client_encoding
+ string = string.dup
key = ['UTF-8', client]
iconv = @@iconvs[key] ||= Iconv.new('UTF-8', client)
iconv.iconv string
end
end