chanoma/characters_set/
punctuations.rs

1//! 全角記号から半角記号の置換テーブルを定義しているモジュールです。
2use crate::corr::{Corr, Correspondence, Item, Linear};
3
4/// 全角記号から半角記号の置換テーブルを保持する構造体です。
5#[derive(Clone)]
6pub struct Punctuations;
7
8impl Corr for Punctuations {
9    fn items(&self) -> Vec<Item> {
10        (Self::EXCLAMATION_MARK
11            + &Self::QUOTATION_MARK
12            + &Self::SHARP
13            + &Self::DOLLER_SIGN
14            + &Self::PERCENT_SIGN
15            + &Self::AMPERSAND
16            + &Self::APOSTROPHE
17            + &Self::LEFT_PARENTHESIS
18            + &Self::RIGHT_PARENTHESIS
19            + &Self::ASTERISK
20            + &Self::PLUS_SIGN
21            + &Self::COMMA
22            + &Self::HYPHEN_MINUS
23            + &Self::FULL_STOP
24            + &Self::SLASH
25            + &Self::COLON
26            + &Self::SEMI_COLON
27            + &Self::LESS_THAN_SIGN
28            + &Self::EQUAL_SIGN
29            + &Self::GREATER_THAN_SIGN
30            + &Self::QUESTION_MARK
31            + &Self::AT_SIGN
32            + &Self::LEFT_SQUARE_BRACKET
33            + &Self::BACKSLASH
34            + &Self::YEN_SIGN
35            + &Self::RIGHT_SQUARE_BRACKET
36            + &Self::CIRCUMFLEX_ACCENT
37            + &Self::LOW_LINE
38            + &Self::GRAVE_ACCENT
39            + &Self::LEFT_CURLY_BRACKET
40            + &Self::VERTICAL_BAR
41            + &Self::RIGHT_CURLY_BRACKET
42            + &Self::TILDE)
43            .items()
44    }
45}
46
47impl Punctuations {
48    /// エクスクラメーションマーク ! (全角) -> ! (半角) の置換です。
49    pub const EXCLAMATION_MARK: Correspondence<Linear> = Linear::new("!", "!").corr();
50    /// ダブルクオーテーション ” (全角) -> " (半角) の置換です。
51    pub const QUOTATION_MARK: Correspondence<Linear> = Linear::new("”", "\"").corr();
52    /// シャープ # (全角) -> # (半角) の置換です。
53    pub const SHARP: Correspondence<Linear> = Linear::new("#", "#").corr();
54    /// ドル $ (全角) -> $ (半角) の置換です。
55    pub const DOLLER_SIGN: Correspondence<Linear> = Linear::new("$", "$").corr();
56    /// パーセント % (全角) -> % (半角) の置換です。
57    pub const PERCENT_SIGN: Correspondence<Linear> = Linear::new("%", "%").corr();
58    /// アンパサンド & (全角) -> & (半角) の置換です。
59    pub const AMPERSAND: Correspondence<Linear> = Linear::new("&", "&").corr();
60    /// シングルクオーテーション ’ (全角) -> ' (半角) の置換です。
61    pub const APOSTROPHE: Correspondence<Linear> = Linear::new("’", "'").corr();
62    /// 丸括弧開き ( (全角) -> ( (半角) の置換です。
63    pub const LEFT_PARENTHESIS: Correspondence<Linear> = Linear::new("(", "(").corr();
64    /// 丸括弧閉じ ) (全角) -> ) (半角) の置換です。
65    pub const RIGHT_PARENTHESIS: Correspondence<Linear> = Linear::new(")", ")").corr();
66    /// アスタリスク * (全角) -> * (半角) の置換です。
67    pub const ASTERISK: Correspondence<Linear> = Linear::new("*", "*").corr();
68    /// プラス + (全角) -> + (半角) の置換です。
69    pub const PLUS_SIGN: Correspondence<Linear> = Linear::new("+", "+").corr();
70    /// カンマ , (全角) -> , (半角) の置換です。
71    pub const COMMA: Correspondence<Linear> = Linear::new(",", ",").corr();
72    /// ハイフン - (全角) -> - (半角) の置換です。
73    pub const HYPHEN_MINUS: Correspondence<Linear> = Linear::new("-", "-").corr();
74    /// ピリオド . (全角) -> . (半角) の置換です。
75    pub const FULL_STOP: Correspondence<Linear> = Linear::new(".", ".").corr();
76    /// スラッシュ / (全角) -> / (半角) の置換です。
77    pub const SLASH: Correspondence<Linear> = Linear::new("/", "/").corr();
78
79    /// コロン : (全角) -> : (半角) の置換です。
80    pub const COLON: Correspondence<Linear> = Linear::new(":", ":").corr();
81    /// セミコロン ; (全角) -> ; (半角) の置換です。
82    pub const SEMI_COLON: Correspondence<Linear> = Linear::new(";", ";").corr();
83    /// 小なり < (全角) -> < (半角) の置換です。
84    pub const LESS_THAN_SIGN: Correspondence<Linear> = Linear::new("<", "<").corr();
85    /// イコール = (全角) -> = (半角) の置換です。
86    pub const EQUAL_SIGN: Correspondence<Linear> = Linear::new("=", "=").corr();
87    /// 大なり > (全角) -> > (半角) の置換です。
88    pub const GREATER_THAN_SIGN: Correspondence<Linear> = Linear::new(">", ">").corr();
89    /// クエスチョンマーク ? (全角) -> ? (半角) の置換です。
90    pub const QUESTION_MARK: Correspondence<Linear> = Linear::new("?", "?").corr();
91    /// アットマーク @ (全角) -> @ (半角) の置換です。
92    pub const AT_SIGN: Correspondence<Linear> = Linear::new("@", "@").corr();
93
94    /// 角括弧開き [ (全角) -> [ (半角) の置換です。
95    pub const LEFT_SQUARE_BRACKET: Correspondence<Linear> = Linear::new("[", "[").corr();
96    /// バックスラッシュ \ (全角) -> \ (半角) の置換です。
97    pub const BACKSLASH: Correspondence<Linear> = Linear::new("\", "\\").corr();
98    /// 円マーク ¥ (全角) -> ¥ (半角) の置換です。
99    pub const YEN_SIGN: Correspondence<Linear> = Linear::new("¥", "¥").corr();
100    /// 角括弧閉じ ] (全角) -> ] (半角) の置換です。
101    pub const RIGHT_SQUARE_BRACKET: Correspondence<Linear> = Linear::new("]", "]").corr();
102    /// キャレット ^ (全角) -> ^ (半角) の置換です。
103    pub const CIRCUMFLEX_ACCENT: Correspondence<Linear> = Linear::new("^", "^").corr();
104    /// アンダースコア _ (全角) -> _ (半角) の置換です。
105    pub const LOW_LINE: Correspondence<Linear> = Linear::new("_", "_").corr();
106    /// バッククオート ` (全角) -> ` (半角) の置換です。
107    pub const GRAVE_ACCENT: Correspondence<Linear> = Linear::new("`", "`").corr();
108
109    /// 波括弧開き { (全角) -> { (半角) の置換です。
110    pub const LEFT_CURLY_BRACKET: Correspondence<Linear> = Linear::new("{", "{").corr();
111    /// バー | (全角) -> | (半角) の置換です。
112    pub const VERTICAL_BAR: Correspondence<Linear> = Linear::new("|", "|").corr();
113    /// 波括弧閉じ } (全角) -> } (半角) の置換です。
114    pub const RIGHT_CURLY_BRACKET: Correspondence<Linear> = Linear::new("}", "}").corr();
115    /// チルダ 〜 (全角) -> ~ (半角) の置換です。
116    pub const TILDE: Correspondence<Linear> = Linear::new("〜", "~").corr();
117
118    pub const fn new() -> Self {
119        Self {}
120    }
121
122    pub const fn corr(self) -> Correspondence<Self> {
123        Correspondence::new(self)
124    }
125}
126
127/// 全角記号から半角記号の置換テーブルの定数です。
128pub const PUNCTUATIONS: Correspondence<Punctuations> = Punctuations::new().corr();