Sha256: ff04f9d3a6f7821c5bb18ceab75525aa64f10d8eaf832f93a88e73e8c39cb8e6

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

# -*- coding: utf-8 -*-

#
# Robust unicode upcase/downcase
#

if RUBY_PLATFORM =~ /java/i
  require 'java'

  puts java.lang.System.getProperty('file.encoding')

  module CiteProc

    def upcase(string)
      java.lang.String.new(string).to_upper_case(java.util.Locale::ENGLISH).to_s
    end

    def downcase(string)
      java.lang.String.new(string).to_lower_case(java.util.Locale::ENGLISH).to_s
    end
  end

else

  module CiteProc

    begin
      require 'unicode'

      def upcase(string)
        Unicode.upcase(string)
      end

      def downcase(string)
        Unicode.downcase(string)
      end
    rescue LoadError
      begin
        require 'unicode_utils'

        def upcase(string)
          UnicodeUtils.upcase(string)
        end

        def downcase(string)
          UnicodeUtils.downcase(string)
        end
      rescue LoadError
        begin
          require 'active_support/multibyte/chars'

          def upcase(string)
            ActiveSupport::Multibyte::Chars.new(string).upcase.to_s
          end

          def downcase(string)
            ActiveSupport::Multibyte::Chars.new(string).downcase.to_s
          end
        rescue LoadError

          def upcase(string)
            string.upcase
          end

          def downcase(string)
            string.downcase
          end
        end
      end
    end
  end
end

module CiteProc
  module_function :upcase, :downcase
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
citeproc-1.0.5 lib/citeproc/compatibility.rb
citeproc-1.0.4 lib/citeproc/compatibility.rb
citeproc-1.0.3 lib/citeproc/compatibility.rb
citeproc-1.0.2 lib/citeproc/compatibility.rb
citeproc-1.0.1 lib/citeproc/compatibility.rb
citeproc-1.0.0 lib/citeproc/compatibility.rb