Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e61753

Browse files
author
Gemmarx
committed
"convert" command
1 parent d0c9e91 commit 2e61753

File tree

8 files changed

+79
-57
lines changed

8 files changed

+79
-57
lines changed

Cargo.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,15 @@ name = "kana"
99
path = "src/kana.rs"
1010

1111
[[bin]]
12-
name = "half2full-kana"
13-
path = "src/half2full-kana.rs"
12+
name = "convert"
13+
path = "src/main.rs"
1414

1515
[[bin]]
1616
name = "canon10n-jp"
1717
path = "src/canon10n-jp.rs"
1818

19-
[[bin]]
20-
name = "normal2wide-ascii"
21-
path = "src/normal2wide-ascii.rs"
22-
23-
[[bin]]
24-
name = "wide2normal-ascii"
25-
path = "src/wide2normal-ascii.rs"
26-
2719
[dependencies]
2820
maplit = "*"
2921
regex = "*"
22+
clap = { version="*", features = ["yaml"] }
3023

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Unicode-JP
2-
==
2+
----
33
Converters of characters included in Japanese texts.
44
- Half-width-kana[半角カナ;HANKAKU KANA] -> normal Katakana
55
- Wide-alphanumeric[全角英数;ZENKAKU EISU] <-> normal ASCII
@@ -67,7 +67,7 @@ convert all separated Voiced-sound-marks into space+combining style "\u{20}\u{30
6767
### Methods of kana::Kana struct:
6868
- half2full(&self, &str) -> String
6969
convert Half-width-kana into normal Katakana with diacritical marks separated [ア゙パ -> ア゙パ]
70-
This is simple but tends to cause trouble when rendering.
70+
This is simple but tends to cause troubles when rendering.
7171
In such a case, use half2kana() or execute vsmark2* as post process.
7272

7373
- half2kana(&self, &str) -> String

src/cli.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: convert
2+
about: Converter of Japanese characters got from STDIN
3+
4+
subcommands:
5+
- wide2ascii:
6+
about: Convert Wide-alphanumeric into normal ASCII
7+
- ascii2wide:
8+
about: Convert normal ASCII characters into Wide-alphanumeric
9+
- hira2kata:
10+
about: Convert Hiragana into Katakana
11+
- kata2hira:
12+
about: Convert Katakana into Hiragana
13+
- vsmark2full:
14+
about: Convert all separated Voiced-sound-marks into full-width style
15+
- vsmark2half:
16+
about: Convert all separated Voiced-sound-marks into half-width style
17+
- vsmark2combi:
18+
about: Convert all separated Voiced-sound-marks into space+combining style
19+
- half2full:
20+
about: Convert Half-width-kana into normal Katakana with diacritical marks separated
21+
- half2kana:
22+
about: Convert Half-width-kana into normal Katakana with diacritical marks combined
23+
- combine:
24+
about: Combine base characters and diacritical marks on Hiragana/Katakana
25+
- nowidespace:
26+
about: Convert Wide-space into normal space

src/half2full-kana.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/kana.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ pub fn wide2ascii(s: &str) -> String {
4747
}
4848

4949
pub fn ascii2wide(s: &str) -> String {
50-
shift_code(|x| 0x20 < x && x < 0x7f, |x| x + 0xfee0, s)
50+
shift_code(|x| 0x0020 < x && x < 0x007f, |x| x + 0xfee0, s)
5151
}
5252

5353
pub fn hira2kata(s: &str) -> String {
54-
shift_code(|x| 0x3041 < x && x < 0x3096, |x| x + 0x60, s)
54+
shift_code(|x| 0x3041 < x && x < 0x3096, |x| x + 0x0060, s)
5555
}
5656

5757
pub fn kata2hira(s: &str) -> String {
58-
shift_code(|x| 0x30A1 < x && x < 0x30F6, |x| x - 0x60, s)
58+
shift_code(|x| 0x30A1 < x && x < 0x30F6, |x| x - 0x0060, s)
5959
}
6060

6161
pub struct Kana {

src/main.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
#[macro_use] extern crate clap;
3+
extern crate kana;
4+
5+
use clap::App;
6+
use kana::Kana;
7+
8+
fn main() {
9+
let clis = load_yaml!("cli.yml");
10+
let args = App::from_yaml(clis).get_matches();
11+
12+
let k = Kana::init();
13+
let r = std::io::stdin();
14+
15+
let buff = &mut String::new();
16+
while r.read_line(buff).is_ok() && 0 != buff.len() {
17+
if args.is_present("ascii2wide") {
18+
print!("{}", kana::ascii2wide(buff));
19+
} else if args.is_present("wide2ascii") {
20+
print!("{}", kana::wide2ascii(buff));
21+
} else if args.is_present("hira2kata") {
22+
print!("{}", kana::hira2kata(buff));
23+
} else if args.is_present("kata2hira") {
24+
print!("{}", kana::kata2hira(buff));
25+
} else if args.is_present("combine") {
26+
print!("{}", k.combine(buff));
27+
} else if args.is_present("half2full") {
28+
print!("{}", k.half2full(buff));
29+
} else if args.is_present("half2kana") {
30+
print!("{}", k.half2kana(buff));
31+
} else if args.is_present("vsmark2half") {
32+
print!("{}", kana::vsmark2half(buff));
33+
} else if args.is_present("vsmark2full") {
34+
print!("{}", kana::vsmark2full(buff));
35+
} else if args.is_present("vsmark2combi") {
36+
print!("{}", kana::vsmark2combi(buff));
37+
} else if args.is_present("nowidespace") {
38+
print!("{}", buff.replace("\u{3000}", "\u{20}"));
39+
} else {
40+
print!("{}", buff);
41+
}
42+
buff.clear();
43+
}
44+
}
45+

src/normal2wide-ascii.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/wide2normal-ascii.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)