Sha256: 77081695e997f5c5a4ecff02b637870d3e8f823bc0a98bf73443a5d111cbb764

Contents?: true

Size: 1.93 KB

Versions: 40

Compression:

Stored size: 1.93 KB

Contents

#!/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//TRANSLIT//IGNORE', 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//TRANSLIT//IGNORE', client)
        iconv.iconv string
      end
    end
  rescue LoadError
    warn "You don't have Iconv support compiled in your Ruby. Spreadsheet may not work as expected"
    def client string, internal='UTF-16LE'
      string.delete "\0"
    end
    def internal string, internal='UTF-16LE'
      string.split('').zip(Array.new(string.size, 0.chr)).join
    end
  end
end

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
spreadsheet-1.1.2 lib/spreadsheet/encodings.rb
spreadsheet-1.1.1 lib/spreadsheet/encodings.rb
spreadsheet-1.1.0 lib/spreadsheet/encodings.rb
spreadsheet-1.0.9 lib/spreadsheet/encodings.rb
spreadsheet-1.0.8 lib/spreadsheet/encodings.rb
spreadsheet-1.0.7 lib/spreadsheet/encodings.rb
spreadsheet-1.0.6 lib/spreadsheet/encodings.rb
spreadsheet-1.0.5 lib/spreadsheet/encodings.rb
spreadsheet-1.0.4 lib/spreadsheet/encodings.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/spreadsheet-1.0.3/lib/spreadsheet/encodings.rb
spreadsheet-1.0.3 lib/spreadsheet/encodings.rb
spreadsheet-1.0.2 lib/spreadsheet/encodings.rb
spreadsheet-1.0.1 lib/spreadsheet/encodings.rb
spreadsheet-1.0.0 lib/spreadsheet/encodings.rb
spreadsheet-0.9.9 lib/spreadsheet/encodings.rb
spreadsheet-0.9.8 lib/spreadsheet/encodings.rb
spreadsheet-0.9.7 lib/spreadsheet/encodings.rb
spreadsheet-0.9.6 lib/spreadsheet/encodings.rb
spreadsheet-0.9.5 lib/spreadsheet/encodings.rb
keeguon-spreadsheet-0.9.3 lib/spreadsheet/encodings.rb