nkf 0.2.0-java
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 +7 -0
- data/.git-blame-ignore-revs +7 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +29 -0
- data/.gitignore +14 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +24 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/java/org/jruby/ext/nkf/Command.java +58 -0
- data/ext/java/org/jruby/ext/nkf/CommandParser.java +70 -0
- data/ext/java/org/jruby/ext/nkf/NKFLibrary.java +13 -0
- data/ext/java/org/jruby/ext/nkf/Option.java +80 -0
- data/ext/java/org/jruby/ext/nkf/Options.java +109 -0
- data/ext/java/org/jruby/ext/nkf/RubyNKF.java +601 -0
- data/ext/nkf/extconf.rb +3 -0
- data/ext/nkf/nkf-utf8/config.h +51 -0
- data/ext/nkf/nkf-utf8/nkf.c +7205 -0
- data/ext/nkf/nkf-utf8/nkf.h +189 -0
- data/ext/nkf/nkf-utf8/utf8tbl.c +14638 -0
- data/ext/nkf/nkf-utf8/utf8tbl.h +72 -0
- data/ext/nkf/nkf.c +506 -0
- data/lib/kconv.rb +283 -0
- data/lib/nkf.jar +0 -0
- data/lib/nkf.rb +6 -0
- data/nkf.gemspec +43 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2a850709cca060466318b74c28bb584377ad4ec325e6440580b70b4f23efd186
|
4
|
+
data.tar.gz: e0944e5dc341458a86616509f877ad4a723b570bd425bed26e74b5a82017efe2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d69a4aad8745e9027653c583cbe4eca6f35a0e3c348a85928ca2802470aaf5acda7fe791a4922edbaf02e61ff26d5ad10d725de885b290bc891979a238ea120c
|
7
|
+
data.tar.gz: 3a3ca9e8c43a8cfc1244318249c2cebb9f0f9f0e6b38d63c5d0809ec8a791b0c4d9817c26c5da05dfd931843130059ba791655ac2af6b8527ed43aa8619265d0
|
@@ -0,0 +1,7 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
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
|
+
runs-on: ${{ matrix.os }}
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v4
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
- name: Install dependencies
|
27
|
+
run: bundle install
|
28
|
+
- name: Run test
|
29
|
+
run: rake compile test
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
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.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
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
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
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__)
|
data/bin/setup
ADDED
@@ -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
|
+
}
|