unf-0.2.0/0000755000004100000410000000000014705470252012337 5ustar www-datawww-dataunf-0.2.0/.github/0000755000004100000410000000000014705470252013677 5ustar www-datawww-dataunf-0.2.0/.github/workflows/0000755000004100000410000000000014705470252015734 5ustar www-datawww-dataunf-0.2.0/.github/workflows/test.yml0000644000004100000410000000237014705470252017440 0ustar www-datawww-dataname: test on: [push, pull_request, workflow_dispatch] jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: engine: cruby min_version: 3.2 build: needs: ruby-versions name: build (${{ matrix.ruby_engine }} / ${{ matrix.ruby_version || 'latest' }} / ${{ matrix.os }}) strategy: matrix: os: - ubuntu-latest ruby_engine: - ruby ruby_version: - '2.0' - '2.7' - '${{ fromJson(needs.ruby-versions.outputs.versions) }}' include: - { os: ubuntu-latest, ruby_engine: jruby, ruby_version: '' } - { os: ubuntu-latest, ruby_engine: jruby, ruby_version: head } - { os: macos-latest, ruby_engine: ruby, ruby_version: '' } - { os: windows-latest, ruby_engine: ruby, ruby_version: ucrt } - { os: windows-latest, ruby_engine: ruby, ruby_version: mswin } runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby_engine }}-${{ matrix.ruby_version }} bundler-cache: true - name: Run test run: bundle exec rake test unf-0.2.0/lib/0000755000004100000410000000000014705470252013105 5ustar www-datawww-dataunf-0.2.0/lib/unf.rb0000644000004100000410000000127214705470252014224 0ustar www-datawww-datarequire 'unf/version' module UNF autoload :Normalizer, 'unf/normalizer' end class String ascii_only = if method_defined?(:ascii_only?) 'ascii_only?' else '/[^\x00-\x7f]/ !~ self' end # :method: to_nfc # Converts the string to NFC. # :method: to_nfd # Converts the string to NFD. # :method: to_nfkc # Converts the string to NFKC. # :method: to_nfkd # Converts the string to NFKD. [:nfc, :nfd, :nfkc, :nfkd].each { |form| eval %{ def to_#{form.to_s} if #{ascii_only} self else UNF::Normalizer.normalize(self, #{form.inspect}) end end } } end unless String.method_defined?(:to_nfc) unf-0.2.0/lib/unf/0000755000004100000410000000000014705470252013675 5ustar www-datawww-dataunf-0.2.0/lib/unf/normalizer_cruby.rb0000644000004100000410000000110714705470252017607 0ustar www-datawww-datacase when defined?(UNF::Normalizer) # Probably unf_ext is preloaded. when String.method_defined?(:unicode_normalize) class String [:nfc, :nfd, :nfkc, :nfkd].each { |form| eval %{ remove_method :to_#{form} if method_defined?(:to_#{form}) def to_#{form} unicode_normalize(#{form.inspect}) end } } end module UNF # :nodoc: all class Normalizer def normalize(string, normalization_form) String.try_convert(string).unicode_normalize(normalization_form) end end end else require 'unf_ext' end unf-0.2.0/lib/unf/normalizer.rb0000644000004100000410000000144014705470252016403 0ustar www-datawww-datarequire 'singleton' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' require 'unf/normalizer_jruby' else require 'unf/normalizer_cruby' end # UTF-8 string normalizer class. Implementations may vary depending # on the platform. class UNF::Normalizer include Singleton class << self # :singleton-method: instance # # Returns a singleton normalizer instance. # :singleton-method: new # # Returns a new normalizer instance. Use +singleton+ instead. public :new # A shortcut for instance.normalize(string, form). def normalize(string, form) instance.normalize(string, form) end end # :method: normalize # :call-seq: # normalize(string, form) # # Normalizes a UTF-8 string into a given form (:nfc, :nfd, :nfkc or # :nfkd). end unf-0.2.0/lib/unf/normalizer_jruby.rb0000644000004100000410000000114014705470252017613 0ustar www-datawww-datarequire 'java' module UNF # :nodoc: all class Normalizer def initialize() @normalizer = java.text.Normalizer end def normalize(string, normalization_form) @normalizer.normalize(string, form(normalization_form)) end private def form(symbol) case symbol when :nfc @normalizer::Form::NFC when :nfd @normalizer::Form::NFD when :nfkc @normalizer::Form::NFKC when :nfkd @normalizer::Form::NFKD else raise ArgumentError, "unknown normalization form: #{symbol.inspect}" end end end end unf-0.2.0/lib/unf/version.rb0000644000004100000410000000004314705470252015704 0ustar www-datawww-datamodule UNF VERSION = '0.2.0' end unf-0.2.0/unf.gemspec0000644000004100000410000000243714705470252014502 0ustar www-datawww-data# -*- encoding: utf-8 -*- require File.expand_path('../lib/unf/version', __FILE__) Gem::Specification.new do |gem| gem.name = "unf" gem.version = UNF::VERSION gem.authors = ["Akinori MUSHA"] gem.email = ["knu@idaemons.org"] gem.description = <<-'EOS' This is a wrapper library to bring Unicode Normalization Form support to Ruby/JRuby. EOS gem.summary = %q{A wrapper library to bring Unicode Normalization Form support to Ruby/JRuby} gem.homepage = "https://github.com/knu/ruby-unf" gem.platform = defined?(JRUBY_VERSION) ? 'java' : Gem::Platform::RUBY gem.license = "BSD-2-Clause" gem.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?(*%w[test/ Rakefile .gitignore .travis.yml]) } gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.require_paths = ["lib"] gem.extra_rdoc_files = ['README.md', 'LICENSE'] gem.required_ruby_version = '>= 1.9.3' gem.extensions = 'ext/mkrf_conf.rb' gem.add_development_dependency 'bundler', '>= 1.2.0' gem.add_development_dependency 'rake', '>= 0.9.2.2' gem.add_development_dependency 'rdoc', '> 2.4.2' gem.add_development_dependency 'test-unit' gem.add_development_dependency 'unf_ext', '>= 0' unless defined?(JRUBY_VERSION) end unf-0.2.0/Gemfile0000644000004100000410000000013014705470252013624 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in unf.gemspec gemspec unf-0.2.0/LICENSE0000644000004100000410000000240714705470252013347 0ustar www-datawww-dataCopyright (c) 2011, 2012 Akinori MUSHA All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. unf-0.2.0/ext/0000755000004100000410000000000014705470252013137 5ustar www-datawww-dataunf-0.2.0/ext/mkrf_conf.rb0000755000004100000410000000126314705470252015435 0ustar www-datawww-data#!/usr/bin/env ruby extdir = File.dirname(__FILE__) unless defined?(JRUBY_VERSION) || String.method_defined?(:unicode_normalize) require 'fileutils' require 'rubygems' require 'rubygems/command.rb' require 'rubygems/dependency_installer.rb' Gem::Command.build_args = ARGV gemsdir = File.expand_path('gems', extdir) installer = Gem::DependencyInstaller.new(install_dir: gemsdir) specs = installer.install('unf_ext', '>= 0') unf_ext = specs.find { |spec| spec.name == 'unf_ext' } FileUtils.cp_r(File.join(unf_ext.gem_dir, 'lib'), File.expand_path('..', extdir)) FileUtils.rm_rf(gemsdir) end File.write(File.expand_path('Rakefile', extdir), < string in NFC } # Class method UNF::Normalizer.normalize(string, :nfc) # Instance methods of String string.to_nfc Installation ------------ gem install unf License ------- Copyright (c) 2011, 2012, 2013 Akinori MUSHA Licensed under the 2-clause BSD license. See `LICENSE` for details. unf-0.2.0/CHANGELOG.md0000644000004100000410000000147514705470252014157 0ustar www-datawww-data## 0.2.0 (2024-08-18) Features: - Use String#unicode_normalize on Ruby >=2.2 unless unf_ext is already loaded. - Reduce the gem size by removing unnecessary files. (GH #22) ## 0.1.4 (2014-04-04) Bugfixes: - Fix the gem platform name for JRuby. ## 0.1.3 (2013-10-25) Features: - Make UNF::Normalizer.instance thread-safe, and deprecate .new. (GH #6) ## 0.1.2 (2013-08-12) Features: - Add license to gemspec. - Adjust dependencies for Ruby 1.8 to satisfy bundler. ## 0.1.1 (2013-03-23) Features: - Add rdoc. ## 0.1.0 (2013-03-18) Features: - Start CI with Travis-CI. ## 0.0.5 (2012-03-04) Features: - Migrate from Jeweler to Bundle gem. Bugfixes: - Fix gem support for JRuby. ## 0.0.4 (2011-12-09) Features: - Introduce autoloading. ## 0.0.3 (2011-10-25) - Initial release.