Sha256: e49aeccb8f052a632c57c41facd38ed2ee4f60c1c558fa68ee7c9e8034dbb4ab

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 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.4'
      def upcase(string)
        string.upcase
      end

      def downcase(string)
        string.downcase
      end
    else
      # Ruby 2.3 and older require extra Gems
      begin
        require 'unicode_utils'
        def upcase(string)
          UnicodeUtils.upcase(string)
        end

        def downcase(string)
          UnicodeUtils.downcase(string)
        end
      rescue LoadError
        begin
          require 'unicode'
          def upcase(string)
            Unicode.upcase(string)
          end

          def downcase(string)
            Unicode.downcase(string)
          end
        rescue LoadError
          warn "CiteProc requires the `unicode_utils` or `unicode` Gem on Ruby 2.3"
        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.1.0 lib/citeproc/compatibility.rb
citeproc-1.0.10 lib/citeproc/compatibility.rb
citeproc-1.0.9 lib/citeproc/compatibility.rb