kakasi 1.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05f73e58cd7e02b7139fa6b6d0c8b77ff7a66b9b
4
+ data.tar.gz: 45b7615fa9d98deefb0cd0fcf2d7976398ddaecd
5
+ SHA512:
6
+ metadata.gz: f0973eb933bab1fd468f0df05f4d3730bb91ebe1d833b13a75d46cf792e9f62530f0031b969cbf998d307499c619ab80f4b783dc05cae430983a6ad2359d6dee
7
+ data.tar.gz: 8c8ce01f0d243ab881338aad83141633e1cea40a6faec1a96cc8ea3d32121d233574228eec7afa6bd1f751c739deeb0f323cecdf8e0d3430c590d6f5c3c4cd40
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ ext/kakasi-config/Makefile
19
+ lib/kakasi/config.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kakasi.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2013 Akinori MUSHA
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
@@ -0,0 +1,51 @@
1
+ # Kakasi for Ruby
2
+
3
+ A Ruby binding for KAKASI implemented with Fiddle/DL/FFI
4
+
5
+ ## Description
6
+
7
+ This library is a port of Ruby/KAKASI to Ruby >=1.9.
8
+
9
+ Ruby/KAKASI was an extention library written by GOTO Kentaro for
10
+ ancient CRuby, which did not work with Ruby >=1.9 or JRuby,
11
+
12
+ This implementation uses Fiddle/DL/FFI as a bridge to libkakasi, so it
13
+ should work with any ruby that supports Fiddle/DL/FFI module, such as:
14
+
15
+ - Ruby 1.9.3 (DL)
16
+ - Ruby 2.0.0+ (Fiddle)
17
+ - Rubinius (Rubinius::FFI)
18
+ - JRuby (FFI)
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'kakasi'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install kakasi
33
+
34
+ ## Usage
35
+
36
+ require 'kakasi'
37
+
38
+ Kakasi.kakasi('-w', 'Rubyから案山子を呼び出せます。')
39
+ #=> "Ruby から 案山子 を 呼び出せ ます 。"
40
+
41
+ ## Links
42
+
43
+ - [KAKASI - Kanji Kana Simple Inverter](http://kakasi.namazu.org/index.html.en)
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ gemspec = Bundler::GemHelper.gemspec
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'test'
8
+ test.test_files = gemspec.test_files
9
+ test.verbose = true
10
+ end
11
+
12
+ require 'rdoc/task'
13
+ Rake::RDocTask.new do |rdoc|
14
+ rdoc.rdoc_dir = 'rdoc'
15
+ rdoc.title = "#{gemspec.name} #{gemspec.version}"
16
+ rdoc.rdoc_files.include(gemspec.extra_rdoc_files)
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
19
+
20
+ task :default => :test
@@ -0,0 +1,94 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+
4
+ $stdout.sync = true
5
+
6
+ dir_config('kakasi')
7
+
8
+ module KakasiExtConf
9
+ default_impl = {
10
+ fiddle: ->{
11
+ require 'fiddle/import'
12
+ extend Fiddle::Importer
13
+ },
14
+
15
+ dl: ->{
16
+ require 'dl/import'
17
+ DL::CPtr.method_defined?(:[]=) or raise "DL::CPtr#[]= is missing"
18
+ extend DL::Importer
19
+ },
20
+
21
+ ffi: ->{
22
+ require 'ffi'
23
+ extend FFI::Library
24
+ },
25
+ }.find { |impl, code|
26
+ print "checking #{impl}... "
27
+ begin
28
+ code.call
29
+ rescue LoadError, StandardError => e
30
+ puts "no (#{e.message})"
31
+ next false
32
+ end
33
+ puts "yes"
34
+ break impl
35
+ } or exit false
36
+
37
+ print 'checking for kakasi... '
38
+
39
+ libkakasi = Enumerator.new { |y|
40
+ libfilename = RbConfig::CONFIG['LIBRUBY_SO'].tap { |so|
41
+ prefix = so[/\A(?:lib|)/]
42
+ suffix = so[/\.(?![0-9]+(?:\.|\z))[^.]+/] or raise 'failed to detect the file extension for dynamic libraries'
43
+ break prefix + 'kakasi' + suffix
44
+ }
45
+
46
+ $LIBPATH.each { |dir|
47
+ y << File.join(dir, libfilename)
48
+ }
49
+ y << 'kakasi'
50
+ y << 'libkakasi'
51
+ y << libfilename
52
+ }.find { |lib|
53
+ begin
54
+ case default_impl
55
+ when :fiddle, :dl
56
+ dlload lib
57
+ when :ffi
58
+ ffi_lib lib
59
+ else
60
+ next false
61
+ end
62
+ puts lib
63
+ true
64
+ rescue LoadError, StandardError
65
+ false
66
+ end
67
+ } or
68
+ begin
69
+ puts 'FAILED!'
70
+ exit false
71
+ end
72
+
73
+ '../../lib/kakasi/config.rb'.tap { |rb|
74
+ puts 'creating %s' % rb
75
+ File.open(File.expand_path(rb, File.dirname(__FILE__)), 'wt') { |f|
76
+ f.print <<-'EOF' % [libkakasi.inspect, default_impl.inspect]
77
+ module Kakasi
78
+ LIBKAKASI = %s unless defined?(LIBKAKASI)
79
+ IMPL = %s unless defined?(IMPL)
80
+ end
81
+ EOF
82
+ }
83
+ }
84
+ end
85
+
86
+ 'Makefile'.tap { |mf|
87
+ puts 'creating %s' % mf
88
+ File.open(mf, 'w') { |f|
89
+ f.print <<-'EOF'
90
+ all:
91
+ install:
92
+ EOF
93
+ }
94
+ }
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'kakasi/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "kakasi"
7
+ spec.version = Kakasi::VERSION
8
+ spec.authors = ["Akinori MUSHA"]
9
+ spec.email = ["knu@idaemons.org"]
10
+ spec.description = %q{A Ruby binding for KAKASI implemented with Fiddle/DL/FFI}
11
+ spec.summary = %q{A Ruby binding for KAKASI implemented with FFI}
12
+ spec.homepage = "https://github.com/knu/kakasi_ffi"
13
+ spec.license = "BSD"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ case RUBY_ENGINE
21
+ when 'jruby'
22
+ spec.platform = 'java'
23
+ else
24
+ spec.extensions = ["ext/kakasi-config/extconf.rb"]
25
+ end
26
+
27
+ spec.required_ruby_version = '>= 1.9.3'
28
+
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rdoc", ["> 2.4.2"]
31
+ spec.add_development_dependency "bundler", [">= 1.2"]
32
+ end
@@ -0,0 +1,28 @@
1
+ require 'kakasi/version'
2
+
3
+ module Kakasi
4
+ case RUBY_ENGINE
5
+ when 'jruby'
6
+ LIBKAKASI = 'kakasi' unless defined?(LIBKAKASI)
7
+ IMPL = :ffi unless defined?(IMPL)
8
+ else
9
+ begin
10
+ require 'kakasi/config'
11
+ rescue LoadError
12
+ require 'rbconfig'
13
+ LIBKAKASI = RbConfig::CONFIG['LIBRUBY_SO'].tap { |so|
14
+ prefix = so[/\A(?:lib|)/]
15
+ suffix = so[/\.(?![0-9]+(?:\.|\z))[^.]+/] or raise 'failed to detect the file extension for dynamic libraries'
16
+ break prefix + 'kakasi' + suffix
17
+ } unless defined?(LIBKAKASI)
18
+ IMPL = :ffi unless defined?(IMPL)
19
+ end
20
+ end
21
+
22
+ require 'kakasi/%s' % IMPL
23
+
24
+ def kakasi(options, string)
25
+ Lib::kakasi(options, string)
26
+ end
27
+ module_function :kakasi
28
+ end
@@ -0,0 +1,9 @@
1
+ module Kakasi
2
+ module Lib
3
+ require 'dl/import'
4
+ Fiddle = DL
5
+ Pointer = DL::CPtr
6
+ end
7
+ end
8
+
9
+ require 'kakasi/fiddle'
@@ -0,0 +1,54 @@
1
+ module Kakasi
2
+ module Lib
3
+ if defined?(Rubinius)
4
+ FFI = Rubinius::FFI
5
+ else
6
+ require 'ffi'
7
+ end
8
+ extend FFI::Library
9
+
10
+ ffi_lib LIBKAKASI
11
+
12
+ attach_function 'kakasi_getopt_argv', [:int, :pointer], :int
13
+ attach_function 'kakasi_do', [:string], :pointer
14
+ attach_function 'kakasi_close_kanwadict', [], :int
15
+ attach_function 'kakasi_free', [:pointer], :int
16
+
17
+ INTERNAL_ENCODING = Encoding::CP932
18
+
19
+ @mutex = Mutex.new
20
+ @options = nil
21
+
22
+ def kakasi(options, string)
23
+ @mutex.synchronize {
24
+ if options != @options
25
+ kakasi_close_kanwadict() if @options
26
+
27
+ args = ['kakasi', *options.split]
28
+
29
+ argc = args.size
30
+ argv = FFI::MemoryPointer.new(:pointer, argc).
31
+ write_array_of_pointer(args.map { |arg|
32
+ FFI::MemoryPointer.from_string(arg)
33
+ })
34
+
35
+ kakasi_getopt_argv(argc, argv).zero? or
36
+ raise "failed to initialize kakasi"
37
+
38
+ @options = options.dup
39
+ end
40
+
41
+ encoding = string.encoding
42
+ result = ''.force_encoding(INTERNAL_ENCODING)
43
+ string.encode(INTERNAL_ENCODING).split(/(\0+)/).each { |str, nul|
44
+ buf = kakasi_do(str)
45
+ result << buf.read_string.force_encoding(INTERNAL_ENCODING)
46
+ kakasi_free(buf)
47
+ result << nul if nul
48
+ }
49
+ result.encode(encoding)
50
+ }
51
+ end
52
+ module_function :kakasi
53
+ end
54
+ end
@@ -0,0 +1,61 @@
1
+ module Kakasi
2
+ module Lib
3
+ require 'fiddle/import' unless defined?(Fiddle::Importer)
4
+
5
+ extend Fiddle::Importer
6
+ include Fiddle
7
+
8
+ case SIZEOF_VOIDP
9
+ when 4
10
+ PackPointers = 'L*'
11
+ when 8
12
+ PackPointers = 'Q*'
13
+ else
14
+ raise 'Unsupported pointer size: %u' % SIZEOF_VOIDP
15
+ end
16
+
17
+ dlload LIBKAKASI
18
+
19
+ extern 'int kakasi_getopt_argv(int, char **)'
20
+ extern 'char *kakasi_do(char *)'
21
+ extern 'int kakasi_close_kanwadict()'
22
+ extern 'int kakasi_free(char *)'
23
+
24
+ INTERNAL_ENCODING = Encoding::CP932
25
+
26
+ @mutex = Mutex.new
27
+ @options = nil
28
+
29
+ def kakasi(options, string)
30
+ @mutex.synchronize {
31
+ if options != @options
32
+ kakasi_close_kanwadict() if @options
33
+
34
+ args = ['kakasi', *options.split]
35
+
36
+ argc = args.size
37
+ argv = Pointer.malloc(argc * SIZEOF_VOIDP)
38
+ argv[0, argv.size] = args.map { |x|
39
+ Pointer[x].to_i
40
+ }.pack(PackPointers)
41
+
42
+ kakasi_getopt_argv(argc, argv).zero? or
43
+ raise "failed to initialize kakasi"
44
+
45
+ @options = options.dup
46
+ end
47
+
48
+ encoding = string.encoding
49
+ result = ''.force_encoding(INTERNAL_ENCODING)
50
+ string.encode(INTERNAL_ENCODING).split(/(\0+)/).each { |str, nul|
51
+ buf = kakasi_do(str)
52
+ result << buf.to_s.force_encoding(INTERNAL_ENCODING)
53
+ kakasi_free(buf)
54
+ result << nul if nul
55
+ }
56
+ result.encode(encoding)
57
+ }
58
+ end
59
+ module_function :kakasi
60
+ end
61
+ end
@@ -0,0 +1,4 @@
1
+ module Kakasi
2
+ KAKASI_VERSION = '2002-09-28'
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'kakasi'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ include Kakasi
5
+
6
+ class TestKakasi < Test::Unit::TestCase
7
+ def test_kakasi
8
+ assert_equal 'KAKASHI nanodesu', eval(<<'', TOPLEVEL_BINDING)
9
+ kakasi('-s -U -Ja -Ha', '案山子なのです')
10
+
11
+ text = '本日は晴れのち曇りです。'
12
+ assert_equal '本日 は 晴れ のち 曇り です 。', Kakasi.kakasi('-w', text)
13
+ assert_equal 'honjitsu ha hare nochi kumori desu .', Kakasi.kakasi('-s -Ja -Ha -Ka -Ea -ka', text)
14
+ assert_equal 'ほんじつ は はれ のち くもり です 。', Kakasi.kakasi('-s -JH -kK', text)
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kakasi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: java
6
+ authors:
7
+ - Akinori MUSHA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>'
32
+ - !ruby/object:Gem::Version
33
+ version: 2.4.2
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>'
37
+ - !ruby/object:Gem::Version
38
+ version: 2.4.2
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
53
+ prerelease: false
54
+ type: :development
55
+ description: A Ruby binding for KAKASI implemented with Fiddle/DL/FFI
56
+ email:
57
+ - knu@idaemons.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - ext/kakasi-config/extconf.rb
68
+ - kakasi.gemspec
69
+ - lib/kakasi.rb
70
+ - lib/kakasi/dl.rb
71
+ - lib/kakasi/ffi.rb
72
+ - lib/kakasi/fiddle.rb
73
+ - lib/kakasi/version.rb
74
+ - test/helper.rb
75
+ - test/test_kakasi.rb
76
+ homepage: https://github.com/knu/kakasi_ffi
77
+ licenses:
78
+ - BSD
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.3
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.1.9
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A Ruby binding for KAKASI implemented with FFI
100
+ test_files:
101
+ - test/helper.rb
102
+ - test/test_kakasi.rb