nkf 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99fe300695064529e277ba99c695e957548f0e636b2901e7eba88a4a62ac5c6c
4
- data.tar.gz: 74a4a2835c227cb45348608c0bb2a206ff8462dfae5df7b803638e254e05572d
3
+ metadata.gz: 80abcab4e210d9e745b5d037d33f5c140a246bdf0639d8918b00941f55f087bf
4
+ data.tar.gz: a2a366513904ff9d4ead77e97b0ef95b94bd3d132bd4248cba2b2f1318c00cdb
5
5
  SHA512:
6
- metadata.gz: c7f58fd74f820302552e7c83271857e63df0d0e622f950570fd1c934efb6f334cc23cf69e8195a26ad79310721a0bb0a06461e098c073c2fefe5be664ae36072
7
- data.tar.gz: 54289152cd0158f6f07d5cbfac794175aa75b510ca20ab7f7d6b13b9a01b76eb78e02d81ae2498ddae5be3565f90f175da0b1686945c6a24f19211ea65f697f6
6
+ metadata.gz: a97fab49ddd1ea39c2ebe55a91eeb2729b1a5a7d3176497d9565cd422eaed8736885d460b82e833a5fab159f866f1204cf79bb5d019720ee7bf106c7ef777116
7
+ data.tar.gz: 74920f57c2595f31afc7666bad29b0f2b8f4919fbadc72c3af1d2dd3e83f16d64c52d20e5cba07cdb93c4b188745cf157c5e32bc76c5b7d83c63d52005be31ff
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
  *.bundle
10
10
  *.dll
11
11
  *.so
12
+ lib/nkf.jar
13
+ .idea
14
+ nkf.iml
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
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.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/Gemfile CHANGED
@@ -1,5 +1,15 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "rake"
4
- gem "rake-compiler"
5
- gem "test-unit"
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "rake"
7
+ gem "rake-compiler"
8
+ gem "test-unit"
9
+ gem "test-unit-ruby-core"
10
+ end
11
+
12
+ group :sig do
13
+ gem "rbs"
14
+ gem "rdoc"
15
+ end
data/LEGAL ADDED
@@ -0,0 +1,26 @@
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.
data/Rakefile CHANGED
@@ -7,6 +7,37 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/test_*.rb"]
8
8
  end
9
9
 
10
- require 'rake/extensiontask'
11
- Rake::ExtensionTask.new("nkf")
10
+ namespace :rbs do
11
+ Rake::TestTask.new(test: :compile) do |t|
12
+ t.libs << "test_sig"
13
+ t.ruby_opts << "-rtest_helper"
14
+ t.test_files = FileList["test_sig/test_*.rb"]
15
+ t.warning = true
16
+ end
17
+
18
+ desc 'Update RBS comments'
19
+ task :annotate do
20
+ require "tmpdir"
21
+
22
+ Dir.mktmpdir do |tmpdir|
23
+ sh("rdoc --ri --output #{tmpdir}/doc --root=. lib")
24
+ sh("rbs annotate --no-system --no-gems --no-site --no-home -d #{tmpdir}/doc sig")
25
+ end
26
+ end
27
+ end
28
+
29
+ if RUBY_ENGINE == "jruby"
30
+ require "rake/javaextensiontask"
31
+ Rake::JavaExtensionTask.new("nkf") do |ext|
32
+ ext.source_version = "1.8"
33
+ ext.target_version = "1.8"
34
+ ext.ext_dir = "ext/java"
35
+ end
36
+
37
+ task :build => :compile
38
+ else
39
+ require 'rake/extensiontask'
40
+ Rake::ExtensionTask.new("nkf")
41
+ end
42
+
12
43
  task :default => :test
@@ -0,0 +1,58 @@
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 <koichiro@meadowy.org>
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<Option> options = new ArrayList<Option>();
35
+ public boolean hasOption(String opt) {
36
+ for (Option option : options) {
37
+ if (opt.equals(option.getOpt())) return true;
38
+ if (opt.equals(option.getLongOpt())) return true;
39
+ }
40
+ return false;
41
+ }
42
+ public void addOption(Option opt) {
43
+ options.add(opt);
44
+ }
45
+ public Option getOption(String opt) {
46
+ for (Option option : options) {
47
+ if (opt.equals(option.getOpt())) return option;
48
+ if (opt.equals(option.getLongOpt())) return option;
49
+ }
50
+ return null;
51
+ }
52
+ public String getOptionValue(String opt) {
53
+ return getOption(opt).getValue();
54
+ }
55
+ public String toString() {
56
+ return options.toString();
57
+ }
58
+ }
@@ -0,0 +1,70 @@
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 <koichiro@meadowy.org>
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
+ public class CommandParser {
31
+ public Command parse(Options opt, String args) {
32
+ Command cc = new Command();
33
+ String[] tokens = args.split("\\s");
34
+ for (int i = 0; i < tokens.length; i++) {
35
+ // long option
36
+ if (tokens[i].startsWith("--")) {
37
+ String s = stripDash(tokens[i]);
38
+ if (opt.hasLongOption(s)) {
39
+ cc.addOption(opt.matchLongOption(s));
40
+ }
41
+ } else {
42
+ // short option
43
+ String s = stripDash(tokens[i]);
44
+ int max = s.length();
45
+ for (int j = 0; j < max; j++) {
46
+ if (opt.hasShortOption(s)) {
47
+ Option cmd = opt.matchShortOption(s);
48
+ if (cmd.getValue() != null) {
49
+ int op_len = cmd.getValue().length();
50
+ s = s.substring(op_len);
51
+ j = j + op_len;
52
+ }
53
+ cc.addOption(cmd);
54
+ }
55
+ s = s.substring(1);
56
+ }
57
+ }
58
+ }
59
+ return cc;
60
+ }
61
+ private String stripDash(String s) {
62
+ if (s.startsWith("--")) {
63
+ return s.substring(2, s.length());
64
+ } else if (s.startsWith("-")) {
65
+ return s.substring(1, s.length());
66
+ } else {
67
+ return s;
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,80 @@
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 <koichiro@meadowy.org>
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.regex.Pattern;
31
+
32
+ public class Option {
33
+ private final String opt;
34
+ private final String longOpt;
35
+ private boolean hasArg = false;
36
+ private String value = null;
37
+ private Pattern pattern;
38
+
39
+ public Option(String opt, String longOpt, String pattern) {
40
+ this.opt = opt;
41
+ this.longOpt = longOpt;
42
+ if (pattern != null) {
43
+ this.hasArg = true;
44
+ this.pattern = Pattern.compile(pattern);
45
+ }
46
+ }
47
+ String getOpt() { return opt; }
48
+ String getLongOpt() { return longOpt; }
49
+ boolean hasShortOpt() {
50
+ return opt != null;
51
+ }
52
+ boolean hasLongOpt() {
53
+ return longOpt != null;
54
+ }
55
+ boolean hasArg() {
56
+ return hasArg;
57
+ }
58
+ public String getValue() {
59
+ return value;
60
+ }
61
+ void setValue(String v) {
62
+ value = v;
63
+ }
64
+ String getKey() {
65
+ if (opt == null)
66
+ return longOpt;
67
+ else
68
+ return opt;
69
+ }
70
+ Pattern pattern() {
71
+ return pattern;
72
+ }
73
+ public String toString() {
74
+ return "[opt: " + opt
75
+ + " longOpt: " + longOpt
76
+ + " hasArg: " + hasArg
77
+ + " pattern: " + pattern
78
+ + " value: " + value + "]";
79
+ }
80
+ }
@@ -0,0 +1,109 @@
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 <koichiro@meadowy.org>
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.Map;
31
+ import java.util.LinkedHashMap;
32
+ import java.util.regex.Matcher;
33
+
34
+ public class Options {
35
+ private final Map<String, Option> shortOpts = new LinkedHashMap<String, Option>();
36
+ private final Map<String, Option> longOpts = new LinkedHashMap<String, Option>();
37
+
38
+ public Options addOption(String opt) {
39
+ return addOption(opt, null);
40
+ }
41
+ public Options addOption(String opt, String longOpt) {
42
+ return addOption(opt, longOpt, null);
43
+ }
44
+ public Options addOption(String opt, String longOpt, String pattern) {
45
+ return addOption(new Option(opt, longOpt, pattern));
46
+ }
47
+ public Options addOption(Option opt) {
48
+ if (opt.hasLongOpt()) {
49
+ longOpts.put(opt.getLongOpt(), opt);
50
+ }
51
+ if (opt.hasShortOpt()) {
52
+ shortOpts.put(opt.getOpt(), opt);
53
+ }
54
+ return this;
55
+ }
56
+ boolean hasShortOption(String opt) {
57
+ for (Map.Entry<String , Option> e : shortOpts.entrySet()) {
58
+ if (opt.startsWith(e.getKey())) {
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+ public Option matchShortOption(String opt) {
65
+ // independent of opt length
66
+ for (Map.Entry<String , Option> e : shortOpts.entrySet()) {
67
+ //System.out.println(opt + " = " + e.getKey());
68
+ if (opt.startsWith(e.getKey())) {
69
+ //System.out.println("match[" + e.getKey() + "]");
70
+ Option cmd = e.getValue();
71
+ if (cmd.hasArg()) {
72
+ Matcher m = cmd.pattern().matcher(opt);
73
+ if (m.find()) {
74
+ //System.out.println("regix[" + m.group() + "]");
75
+ cmd.setValue(m.group());
76
+ }
77
+ }
78
+ return cmd;
79
+ }
80
+ }
81
+ return null;
82
+ }
83
+ boolean hasLongOption(String opt) {
84
+ for (Map.Entry<String , Option> e : longOpts.entrySet()) {
85
+ if (opt.startsWith(e.getKey())) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ Option matchLongOption(String opt) {
92
+ for (Map.Entry<String , Option> e : longOpts.entrySet()) {
93
+ //System.out.println(opt + " = " + e.getKey());
94
+ if (opt.startsWith(e.getKey())) {
95
+ //System.out.println("match[" + e.getKey() + "]");
96
+ Option cmd = e.getValue();
97
+ if (cmd.hasArg()) {
98
+ Matcher m = cmd.pattern().matcher(opt);
99
+ if (m.find()) {
100
+ //System.out.println("regix[" + m.group() + "]");
101
+ cmd.setValue(m.group(1));
102
+ }
103
+ }
104
+ return cmd;
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+ }