├── ext ├── nkf │ ├── extconf.rb │ ├── nkf-utf8 │ │ ├── config.h │ │ ├── utf8tbl.h │ │ └── nkf.h │ └── nkf.c └── java │ └── org │ └── jruby │ └── ext │ └── nkf │ ├── NKFLibrary.java │ ├── Command.java │ ├── Option.java │ ├── CommandParser.java │ ├── Options.java │ └── RubyNKF.java ├── Gemfile ├── lib ├── nkf.rb └── kconv.rb ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── bin ├── setup └── console ├── .gitignore ├── .git-blame-ignore-revs ├── Rakefile ├── test └── nkf │ ├── test_nkf.rb │ └── test_kconv.rb ├── LEGAL ├── README.md ├── BSDL ├── nkf.gemspec └── COPYING /ext/nkf/extconf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | require 'mkmf' 3 | create_makefile('nkf') 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem "rake" 4 | gem "rake-compiler" 5 | gem "test-unit" 6 | -------------------------------------------------------------------------------- /lib/nkf.rb: -------------------------------------------------------------------------------- 1 | if RUBY_ENGINE == "jruby" 2 | require 'nkf.jar' 3 | JRuby::Util.load_ext('org.jruby.ext.nkf.NKFLibrary') 4 | else 5 | require 'nkf.so' 6 | end 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: 'github-actions' 4 | directory: '/' 5 | schedule: 6 | interval: 'weekly' 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | *.bundle 10 | *.dll 11 | *.so 12 | lib/nkf.jar 13 | .idea 14 | nkf.iml 15 | -------------------------------------------------------------------------------- /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # This is a file used by GitHub to ignore the following commits on `git blame`. 2 | # 3 | # You can also do the same thing in your local repository with: 4 | # $ git config --local blame.ignoreRevsFile .git-blame-ignore-revs 5 | 6 | # Expand tabs 7 | 564b86c8de70b636d94df815c77c5989a7a45c3b 8 | -------------------------------------------------------------------------------- /ext/java/org/jruby/ext/nkf/NKFLibrary.java: -------------------------------------------------------------------------------- 1 | package org.jruby.ext.nkf; 2 | 3 | import org.jruby.Ruby; 4 | import org.jruby.runtime.load.Library; 5 | 6 | import java.io.IOException; 7 | 8 | public class NKFLibrary implements Library { 9 | @Override 10 | public void load(Ruby ruby, boolean b) throws IOException { 11 | RubyNKF.load(ruby); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "nkf" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rake/testtask" 3 | 4 | Rake::TestTask.new(:test) do |t| 5 | t.libs << "test" 6 | t.libs << "lib" 7 | t.test_files = FileList["test/**/test_*.rb"] 8 | end 9 | 10 | if RUBY_ENGINE == "jruby" 11 | require "rake/javaextensiontask" 12 | Rake::JavaExtensionTask.new("nkf") do |ext| 13 | ext.source_version = "1.8" 14 | ext.target_version = "1.8" 15 | ext.ext_dir = "ext/java" 16 | end 17 | 18 | task :build => :compile 19 | else 20 | require 'rake/extensiontask' 21 | Rake::ExtensionTask.new("nkf") 22 | end 23 | 24 | task :default => :test 25 | -------------------------------------------------------------------------------- /test/nkf/test_nkf.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: false 2 | require 'test/unit' 3 | require 'nkf' 4 | 5 | class TestNKF < Test::Unit::TestCase 6 | EUC_STR = "\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\ 7 | \xa5\xb9\xa5\xaf\xa5\xea\xa5\xd7\xa5\xc8\xb8\xc0\xb8\xec\ 8 | Ruby" 9 | 10 | def test_guess 11 | str_euc = EUC_STR 12 | str_jis = NKF.nkf('-j', str_euc) 13 | assert_equal(::NKF::JIS, NKF.guess(str_jis)) 14 | assert_equal(::NKF::EUC, NKF.guess(str_euc)) 15 | end 16 | 17 | def test_ruby_dev_36909 18 | assert_nothing_raised do 19 | 100.times { NKF.nkf("--oc=eucJP-nkf", "foo") } 20 | end 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ruby-versions: 7 | uses: ruby/actions/.github/workflows/ruby_versions.yml@master 8 | with: 9 | engine: cruby-jruby 10 | min_version: 2.5 11 | 12 | build: 13 | needs: ruby-versions 14 | name: build (${{ matrix.ruby }} / ${{ matrix.os }}) 15 | strategy: 16 | matrix: 17 | ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }} 18 | os: [ ubuntu-latest, macos-latest ] 19 | exclude: 20 | - ruby: 2.5 21 | os: macos-latest 22 | runs-on: ${{ matrix.os }} 23 | steps: 24 | - uses: actions/checkout@v6 25 | - name: Set up Ruby 26 | uses: ruby/setup-ruby@v1 27 | with: 28 | ruby-version: ${{ matrix.ruby }} 29 | - name: Install dependencies 30 | run: bundle install 31 | - name: Run test 32 | run: rake compile test 33 | -------------------------------------------------------------------------------- /LEGAL: -------------------------------------------------------------------------------- 1 | # -*- rdoc -*- 2 | 3 | = LEGAL NOTICE INFORMATION 4 | -------------------------- 5 | 6 | All the files in this distribution are covered under either the Ruby's 7 | license (see the file COPYING) or public-domain except some files 8 | mentioned below. 9 | 10 | [ext/nkf/nkf-utf8/config.h] 11 | [ext/nkf/nkf-utf8/nkf.c] 12 | [ext/nkf/nkf-utf8/utf8tbl.c] 13 | 14 | These files are under the following license. So to speak, it is 15 | copyrighted semi-public-domain software. 16 | 17 | >>> 18 | Copyright (C) 1987:: Fujitsu LTD. (Itaru ICHIKAWA) 19 | 20 | Everyone is permitted to do anything on this program 21 | including copying, modifying, improving, 22 | as long as you don't try to pretend that you wrote it. 23 | i.e., the above copyright notice has to appear in all copies. 24 | Binary distribution requires original version messages. 25 | You don't have to ask before copying, redistribution or publishing. 26 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NKF 2 | 3 | This is a Ruby Extension version of nkf (Network Kanji Filter). 4 | It converts the first argument and returns converted result. Conversion 5 | details are specified by flags as the first argument. 6 | 7 | ## Installation 8 | 9 | Add this line to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'nkf' 13 | ``` 14 | 15 | And then execute: 16 | 17 | $ bundle install 18 | 19 | Or install it yourself as: 20 | 21 | $ gem install nkf 22 | 23 | ## Usage 24 | 25 | ```ruby 26 | require 'nkf' 27 | output = NKF.nkf("-s", input) 28 | ``` 29 | 30 | ## Development 31 | 32 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 33 | 34 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 35 | 36 | ## Contributing 37 | 38 | Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/nkf. 39 | -------------------------------------------------------------------------------- /ext/nkf/nkf-utf8/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | /* UTF8 input and output */ 5 | #define UTF8_INPUT_ENABLE 6 | #define UTF8_OUTPUT_ENABLE 7 | 8 | /* invert characters invalid in Shift_JIS to CP932 */ 9 | #define SHIFTJIS_CP932 10 | 11 | /* fix input encoding when given by option */ 12 | #define INPUT_CODE_FIX 13 | 14 | /* --overwrite option */ 15 | /* by Satoru Takabayashi */ 16 | #define OVERWRITE 17 | 18 | /* --cap-input, --url-input option */ 19 | #define INPUT_OPTION 20 | 21 | /* --numchar-input option */ 22 | #define NUMCHAR_OPTION 23 | 24 | /* --debug, --no-output option */ 25 | #define CHECK_OPTION 26 | 27 | /* JIS X0212 */ 28 | #define X0212_ENABLE 29 | 30 | /* --exec-in, --exec-out option 31 | * require pipe, fork, execvp and so on. 32 | * please undef this on MS-DOS, MinGW 33 | * this is still buggy around child process 34 | */ 35 | /* #define EXEC_IO */ 36 | 37 | /* Unicode Normalization */ 38 | #define UNICODE_NORMALIZATION 39 | 40 | /* 41 | * Select Default Output Encoding 42 | * 43 | */ 44 | 45 | /* #define DEFAULT_CODE_JIS */ 46 | /* #define DEFAULT_CODE_SJIS */ 47 | /* #define DEFAULT_CODE_WINDOWS_31J */ 48 | /* #define DEFAULT_CODE_EUC */ 49 | /* #define DEFAULT_CODE_UTF8 */ 50 | 51 | #endif /* _CONFIG_H_ */ 52 | -------------------------------------------------------------------------------- /BSDL: -------------------------------------------------------------------------------- 1 | Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions 5 | are met: 6 | 1. Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 | SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /nkf.gemspec: -------------------------------------------------------------------------------- 1 | source_version = ["", "ext/nkf/"].find do |dir| 2 | begin 3 | break File.open(File.join(__dir__, "#{dir}nkf.c")) {|f| 4 | f.gets("\n#define NKF_GEM_VERSION ") 5 | f.gets[/\s*"(.+)"/, 1] 6 | } 7 | rescue Errno::ENOENT 8 | end 9 | end 10 | 11 | Gem::Specification.new do |spec| 12 | spec.name = "nkf" 13 | spec.version = source_version 14 | spec.authors = ["NARUSE Yui", "Charles Oliver Nutter"] 15 | spec.email = ["naruse@airemix.jp", "headius@headius.com"] 16 | 17 | spec.summary = %q{Ruby extension for Network Kanji Filter} 18 | spec.description = %q{Ruby extension for Network Kanji Filter} 19 | spec.homepage = "https://github.com/ruby/nkf" 20 | spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0") 21 | spec.licenses = ["Ruby", "BSD-2-Clause"] 22 | 23 | spec.metadata["homepage_uri"] = spec.homepage 24 | spec.metadata["source_code_uri"] = spec.homepage 25 | spec.metadata["changelog_uri"] = spec.homepage + "/releases" 26 | 27 | # Specify which files should be added to the gem when it is released. 28 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 29 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 30 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 31 | end 32 | 33 | if Gem::Platform === spec.platform and spec.platform =~ 'java' or RUBY_ENGINE == 'jruby' 34 | spec.platform = 'java' 35 | spec.licenses += ["EPL-2.0", "LGPL-2.1"] 36 | spec.files += Dir["lib/nkf.jar"] 37 | else 38 | spec.extensions = ["ext/nkf/extconf.rb"] 39 | end 40 | 41 | spec.bindir = "exe" 42 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 43 | spec.require_paths = ["lib"] 44 | end 45 | -------------------------------------------------------------------------------- /ext/java/org/jruby/ext/nkf/Command.java: -------------------------------------------------------------------------------- 1 | /***** BEGIN LICENSE BLOCK ***** 2 | * Version: EPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Eclipse Public 5 | * License Version 2.0 (the "License"); you may not use this file 6 | * except in compliance with the License. You may obtain a copy of 7 | * the License at http://www.eclipse.org/legal/epl-v20.html 8 | * 9 | * Software distributed under the License is distributed on an "AS 10 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 11 | * implied. See the License for the specific language governing 12 | * rights and limitations under the License. 13 | * 14 | * Copyright (C) 2011 Koichiro Ohba 15 | * 16 | * Alternatively, the contents of this file may be used under the terms of 17 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 18 | * in which case the provisions of the LGPL are applicable instead 19 | * of those above. If you wish to allow use of your version of this file only 20 | * under the terms of either the LGPL, and not to allow others to 21 | * use your version of this file under the terms of the EPL, indicate your 22 | * decision by deleting the provisions above and replace them with the notice 23 | * and other provisions required by the LGPL. If you do not delete 24 | * the provisions above, a recipient may use your version of this file under 25 | * the terms of any one of the EPL, the LGPL. 26 | ***** END LICENSE BLOCK *****/ 27 | 28 | package org.jruby.ext.nkf; 29 | 30 | import java.util.List; 31 | import java.util.ArrayList; 32 | 33 | public class Command { 34 | private final List