From 5de9a5c063f08bcadeff3695a056183f4d86acca Mon Sep 17 00:00:00 2001 From: ItsukiYamada Date: Thu, 14 Dec 2023 11:07:30 +0900 Subject: [PATCH 1/4] :up:update: regex version -> 1.10.2 --- Cargo.lock | 158 ++++++++++++++++++++-------------------------------- Cargo.toml | 2 +- src/kana.rs | 2 +- 3 files changed, 61 insertions(+), 101 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fbff8f..4ec3fad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,214 +1,174 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" -version = "0.5.3" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr", ] [[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi", ] [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "hermit-abi", + "libc", + "winapi", ] [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "clap" version = "2.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", + "yaml-rust", ] [[package]] name = "hermit-abi" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.68" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" [[package]] name = "memchr" -version = "0.1.11" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "regex" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "regex" -version = "0.1.80" +name = "regex-automata" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ - "aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick", + "memchr", + "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.3.9" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" dependencies = [ - "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] [[package]] name = "unicode-jp" version = "0.4.0" dependencies = [ - "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", + "clap", + "lazy_static", + "regex", ] [[package]] name = "unicode-width" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" [[package]] name = "vec_map" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" [[package]] name = "winapi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "yaml-rust" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" -"checksum hermit-abi 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum libc 0.2.68 (registry+https://github.com/rust-lang/crates.io-index)" = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" -"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" -"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" -"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" -"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" -"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" -"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" -"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" +checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" diff --git a/Cargo.toml b/Cargo.toml index 5ae842a..da9035d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ name = "converchar-jp" path = "src/main.rs" [dependencies] -regex = "0.1.80" +regex = "1.10.2" clap = { version="2.33.0", features = ["yaml"] } lazy_static = "1.4.0" diff --git a/src/kana.rs b/src/kana.rs index 799c254..7769aa3 100644 --- a/src/kana.rs +++ b/src/kana.rs @@ -364,7 +364,7 @@ fn replace_marks(vmark: &str, svmark: &str, src: &str) -> String { static ref RE2: Regex = Regex::new(RE_SEMIVOICED_MARKS).unwrap(); } let s_ = RE1.replace_all(src, vmark); - RE2.replace_all(&s_, svmark) + RE2.replace_all(&s_, svmark).into_owned() } /// Convert all separated Voiced-sound-marks into half-width style "\u{FF9E}" From 5a9540f0b0865c06aa6285af720f50f336595b4b Mon Sep 17 00:00:00 2001 From: ItsukiYamada Date: Thu, 14 Dec 2023 11:13:40 +0900 Subject: [PATCH 2/4] :art:style: cargo clippy --- src/kana.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/kana.rs b/src/kana.rs index 7769aa3..e514fa0 100644 --- a/src/kana.rs +++ b/src/kana.rs @@ -46,14 +46,14 @@ const CH_VOICED_HALF: char = '\u{FF9E}'; const CH_SEMIVOICED_HALF: char = '\u{FF9F}'; const CH_SPACE: char = '\u{20}'; -const VOICED_COMBI: &'static str = "\u{3099}"; -const SEMIVOICED_COMBI: &'static str = "\u{309A}"; -const VOICED_WITH_SPACE: &'static str = "\u{20}\u{3099}"; -const SEMIVOICED_WITH_SPACE: &'static str = "\u{20}\u{309A}"; +const VOICED_COMBI: &str = "\u{3099}"; +const SEMIVOICED_COMBI: &str = "\u{309A}"; +const VOICED_WITH_SPACE: &str = "\u{20}\u{3099}"; +const SEMIVOICED_WITH_SPACE: &str = "\u{20}\u{309A}"; -const RE_VOICED_MARKS: &'static str +const RE_VOICED_MARKS: &str = r"(?:\x20??\x{3099}|\x{309B}|\x{FF9E})"; -const RE_SEMIVOICED_MARKS: &'static str +const RE_SEMIVOICED_MARKS: &str = r"(?:\x20??\x{309A}|\x{309C}|\x{FF9F})"; lazy_static! { @@ -257,7 +257,7 @@ pub fn ascii2wide(s: &str) -> String { /// assert_eq!("イロハァィゥヴヵヶ", kana::hira2kata("いろはぁぃぅゔゕゖ")); /// ``` pub fn hira2kata(s: &str) -> String { - shift_code(|x| 0x3041 <= x && x <= 0x3096, |x| x + 0x0060, s) + shift_code(|x| (0x3041..=0x3096).contains(&x), |x| x + 0x0060, s) } /// Convert Katakana into Hiragana [ア -> あ] @@ -266,7 +266,7 @@ pub fn hira2kata(s: &str) -> String { /// assert_eq!("いろはぁぃぅゔゕゖ", kana::kata2hira("イロハァィゥヴヵヶ")); /// ``` pub fn kata2hira(s: &str) -> String { - shift_code(|x| 0x30A1 <= x && x <= 0x30F6, |x| x - 0x0060, s) + shift_code(|x| (0x30A1..=0x30F6).contains(&x), |x| x - 0x0060, s) } macro_rules! push_content { @@ -393,20 +393,20 @@ pub fn vsmark2full(s: &str) -> String { /// assert_eq!("ひ ゚ひ ゙んは ゙", kana::vsmark2combi("ぴひ゛んは ゙")); /// ``` pub fn vsmark2combi(s: &str) -> String { - replace_marks(&VOICED_WITH_SPACE, &SEMIVOICED_WITH_SPACE, s) + replace_marks(VOICED_WITH_SPACE, SEMIVOICED_WITH_SPACE, s) } /// Convert Wide-space into normal space [" " -> " "] -pub fn nowidespace(s: &str) -> String { s.replace("\u{3000}", "\u{20}") } +pub fn nowidespace(s: &str) -> String { s.replace('\u{3000}', "\u{20}") } /// Convert normal space into Wide-space [" " -> " "] -pub fn space2wide(s: &str) -> String { s.replace("\u{20}", "\u{3000}") } +pub fn space2wide(s: &str) -> String { s.replace('\u{20}', "\u{3000}") } /// Convert Wide-yen into Half-width-yen ["¥" -> "¥"] -pub fn nowideyen(s: &str) -> String { s.replace("\u{ffe5}", "\u{a5}") } +pub fn nowideyen(s: &str) -> String { s.replace('\u{ffe5}', "\u{a5}") } /// Convert Half-width-yen into Wide-yen ["¥" -> "¥"] -pub fn yen2wide(s: &str) -> String { s.replace("\u{a5}", "\u{ffe5}") } +pub fn yen2wide(s: &str) -> String { s.replace('\u{a5}', "\u{ffe5}") } #[cfg(test)] From 60b1028b420a5ad3223711c6c3665bc7a7fd3069 Mon Sep 17 00:00:00 2001 From: ItsukiYamada Date: Thu, 14 Dec 2023 17:55:39 +0900 Subject: [PATCH 3/4] :recycle:refactor: clap version :up: & drop yaml --- Cargo.lock | 217 ++++++++++++++++++++++++++++++++++++++-------------- Cargo.toml | 4 +- src/kana.rs | 7 +- src/main.rs | 161 ++++++++++++++++++++++++++++---------- 4 files changed, 283 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ec3fad..6631b6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,67 +12,110 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.11.0" +name = "anstream" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" dependencies = [ - "winapi", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "atty" -version = "0.2.14" +name = "anstyle" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "windows-sys", ] [[package]] -name = "bitflags" -version = "1.2.1" +name = "anstyle-wincon" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", +] [[package]] name = "clap" -version = "2.33.0" +version = "4.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" dependencies = [ - "ansi_term", - "atty", - "bitflags", + "anstream", + "anstyle", + "clap_lex", "strsim", - "textwrap", - "unicode-width", - "vec_map", - "yaml-rust", ] [[package]] -name = "hermit-abi" -version = "0.1.10" +name = "clap_derive" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ - "libc", + "heck", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "clap_lex" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] -name = "libc" -version = "0.2.68" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "memchr" @@ -80,6 +123,24 @@ version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + [[package]] name = "regex" version = "1.10.2" @@ -111,19 +172,27 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] -name = "textwrap" -version = "0.11.0" +name = "syn" +version = "2.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" dependencies = [ - "unicode-width", + "proc-macro2", + "quote", + "unicode-ident", ] +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "unicode-jp" version = "0.4.0" @@ -134,41 +203,73 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.7" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "vec_map" -version = "0.8.1" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] [[package]] -name = "winapi" -version = "0.3.8" +name = "windows-targets" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" [[package]] -name = "yaml-rust" -version = "0.3.5" +name = "windows_x86_64_msvc" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/Cargo.toml b/Cargo.toml index da9035d..04c5f56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "unicode-jp" version = "0.4.0" authors = ["gemmarx "] +edition = "2021" description = "A library to convert Japanese Half-width-kana[半角カナ] and Wide-alphanumeric[全角英数] into normal ones." repository = "https://github.com/gemmarx/unicode-jp-rs" @@ -21,6 +22,5 @@ path = "src/main.rs" [dependencies] regex = "1.10.2" -clap = { version="2.33.0", features = ["yaml"] } +clap = { version="4.4.11", features=["derive"] } lazy_static = "1.4.0" - diff --git a/src/kana.rs b/src/kana.rs index e514fa0..84d2f79 100644 --- a/src/kana.rs +++ b/src/kana.rs @@ -23,9 +23,6 @@ //! } //! ``` -#[macro_use] extern crate lazy_static; -extern crate regex; - use std::char; use std::collections::HashMap; use regex::Regex; @@ -56,7 +53,7 @@ const RE_VOICED_MARKS: &str const RE_SEMIVOICED_MARKS: &str = r"(?:\x20??\x{309A}|\x{309C}|\x{FF9F})"; -lazy_static! { +lazy_static::lazy_static! { static ref SEMIVOICED_HALVES: HashMap = [ ('\u{FF8A}', '\u{30D1}'), // ハ FF8A パ 30D1 ('\u{FF8B}', '\u{30D4}'), // ヒ FF8B ピ 30D4 @@ -359,7 +356,7 @@ fn enspace(s: &str) -> String { } fn replace_marks(vmark: &str, svmark: &str, src: &str) -> String { - lazy_static! { + lazy_static::lazy_static! { static ref RE1: Regex = Regex::new(RE_VOICED_MARKS).unwrap(); static ref RE2: Regex = Regex::new(RE_SEMIVOICED_MARKS).unwrap(); } diff --git a/src/main.rs b/src/main.rs index 8d14278..9e49c48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,61 +1,140 @@ +mod kana; -#[macro_use] extern crate lazy_static; -#[macro_use] extern crate clap; -extern crate kana; - +use clap::Parser; +use kana::*; use std::error::Error; -use std::{io, process, fs}; use std::io::prelude::*; -use clap::ArgMatches; -use kana::*; +use std::{fs, io, process}; -macro_rules! err { ($e:expr) => ( { - writeln!(&mut io::stderr(), "{}", $e).unwrap(); - process::exit(1); -} ) } +macro_rules! err { + ($e:expr) => {{ + writeln!(&mut io::stderr(), "{}", $e).unwrap(); + process::exit(1); + }}; +} -fn main() { - let _args = load_yaml!("cli.yml"); - let args = clap::App::from_yaml(_args).get_matches(); +macro_rules! command { + ($($name:ident,)*) => { + #[derive(Parser, Debug)] + pub struct Command { + $( + #[arg(long)] + $name: bool, + )* + input: Option, + } + }; +} +command!( + half2full, + half2kana, + combine, + hira2kata, + kata2hira, + vsmark2half, + vsmark2full, + vsmark2combi, + ascii2wide, + wide2ascii, + nowidespace, + space2wide, + nowideyen, + yen2wide, +); + +fn main() { + let args = Command::parse(); match main_body(&args, get_input_clap(&args)) { - Ok(_) => {}, + Ok(_) => {} Err(e) => err!(e), } } -fn main_body(args: &ArgMatches, input: Box) - -> Result<(), Box> -{ +macro_rules! get_converter_macro { + ($args:ident, $($name:ident,)*) => { + $( + if $args.$name { + return $name; + } + )* + }; +} + +fn get_converter(args: &Command) -> for<'a> fn(&'a str) -> String { + get_converter_macro!( + args, + half2full, + half2kana, + combine, + hira2kata, + kata2hira, + vsmark2half, + vsmark2full, + vsmark2combi, + ascii2wide, + wide2ascii, + nowidespace, + space2wide, + nowideyen, + yen2wide, + ); + panic!(); +} + +fn main_body(args: &Command, input: Input) -> Result<(), Box> { + let converter = get_converter(args); + for _s in input.lines() { - let mut s = _s?; - if args.is_present("half2full") { s = half2full(&s); } - if args.is_present("half2kana") { s = half2kana(&s); } - if args.is_present("combine") { s = combine(&s); } - if args.is_present("hira2kata") { s = hira2kata(&s); } - if args.is_present("kata2hira") { s = kata2hira(&s); } - if args.is_present("vsmark2half") { s = vsmark2half(&s); } - if args.is_present("vsmark2full") { s = vsmark2full(&s); } - if args.is_present("vsmark2combi") { s = vsmark2combi(&s); } - if args.is_present("ascii2wide") { s = ascii2wide(&s); } - if args.is_present("wide2ascii") { s = wide2ascii(&s); } - if args.is_present("nowidespace") { s = nowidespace(&s); } - if args.is_present("space2wide") { s = space2wide(&s); } - if args.is_present("nowideyen") { s = nowideyen(&s); } - if args.is_present("yen2wide") { s = yen2wide(&s); } - println!("{}", s); + let s = _s?; + println!("{}", converter(&converter(&s))); } Ok(()) } -fn get_input_clap(args: &ArgMatches) -> Box { - if args.is_present("INPUT") { - let f = fs::File::open(args.value_of("INPUT").unwrap()) - .unwrap_or_else(|e|err!(e)); - Box::new(io::BufReader::new(f)) as Box +fn get_input_clap(args: &Command) -> Input { + if let Some(input) = &&args.input { + let f = fs::File::open(input).unwrap_or_else(|e| err!(e)); + Input::BufReader(io::BufReader::new(f)) } else { - lazy_static! { static ref STDIN: io::Stdin = io::stdin(); } - Box::new(STDIN.lock()) as Box + let stdin = io::stdin(); + let lock = stdin.lock(); + Input::Stdio { + stdin, + lock, + } } } +pub enum Input { + BufReader(io::BufReader), + Stdio { + stdin: io::Stdin, + lock: io::StdinLock<'static>, + }, +} + +impl Read for Input { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + match self { + Self::BufReader(reader) => reader.read(buf), + Self::Stdio { stdin, .. } => stdin.read(buf), + } + } +} + +impl BufRead for Input { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + match self { + Self::BufReader(reader) => reader.fill_buf(), + Self::Stdio { lock, .. } => lock.fill_buf(), + } + } + + fn consume(&mut self, amt: usize) { + match self { + Self::BufReader(reader) => reader.consume(amt), + Self::Stdio { lock, .. } => lock.consume(amt), + } + } +} From d7ab818b35af105ad7dbfaa93dbc295c67342448 Mon Sep 17 00:00:00 2001 From: maaaashi Date: Fri, 15 Dec 2023 11:16:20 +0900 Subject: [PATCH 4/4] =?UTF-8?q?version=E3=81=AE=E8=A8=AD=E5=AE=9A=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04c5f56..51a9813 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,6 @@ name = "converchar-jp" path = "src/main.rs" [dependencies] -regex = "1.10.2" -clap = { version="4.4.11", features=["derive"] } +regex = "^1.10.2" +clap = { version="^4.4.11", features=["derive"] } lazy_static = "1.4.0"