1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
extern crate clap;
extern crate kelp;
use clap::{App, Arg};
use kelp::h2z;
use kelp::hira2hkata;
use kelp::hira2kata;
use kelp::kata2hira;
use kelp::z2h;
use kelp::conv_option::ConvOption;
fn main() {
let matches = App::new("kelp")
.version("0.1")
.author("Taro Yamashita <taro.ymst@gmail.com>")
.about("A conversion tool of Japanese")
.arg(Arg::with_name("INPUT")
.required(true)
.help("A text that you want to convert"))
.arg(Arg::with_name("convert")
.short("c")
.long("conv")
.takes_value(true)
.help("Specified conversion pattern"))
.arg(Arg::with_name("ascii")
.short("a")
.long("ascii")
.help("Convert with ascii if specified"))
.arg(Arg::with_name("digit")
.short("d")
.long("digit")
.help("Convert with digit if specified"))
.arg(Arg::with_name("kana")
.short("k")
.long("kana")
.help("Convert with kana if specified"))
.arg(Arg::with_name("ignore")
.short("i")
.long("ignore")
.takes_value(true)
.help("Specified ignore characters"))
.get_matches();
let option = ConvOption::build()
.ascii(matches.is_present("ascii"))
.digit(matches.is_present("digit"))
.kana(matches.is_present("digit"))
.ignore(matches.value_of("ignore").unwrap_or(""))
.finalize();
let text = matches.value_of("INPUT").unwrap();
let converted = match matches.value_of("convert") {
Some(s) if s == "h2z" => h2z(text, option),
Some(s) if s == "h2hk" => hira2hkata(text, option),
Some(s) if s == "h2k" => hira2kata(text, option),
Some(s) if s == "k2h" => kata2hira(text, option),
Some(s) if s == "z2h" => z2h(text, option),
_ => text.to_string(),
};
println!("{}", converted);
}