Sha256: 9fc61872284f72ed4bda1e7b125e507c099276d1a7912a8aaa228bd116d0d146

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 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
    if RUBY_VERSION >= '2.3'
      def upcase(string)
        string.upcase
      end

      def downcase(string)
        string.downcase
      end
    else
      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
          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

            def upcase(string)
              string.upcase
            end

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

module CiteProc
  module_function :upcase, :downcase
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
citeproc-1.0.8 lib/citeproc/compatibility.rb
citeproc-1.0.7 lib/citeproc/compatibility.rb
citeproc-1.0.6 lib/citeproc/compatibility.rb