japanese_address_parser/formatter/
fullwidth_character.rs

1/// 文字列中の全角数字を半角数字に修正します
2pub(crate) fn format_fullwidth_numerals(target: &str) -> String {
3    target
4        .chars()
5        .map(|c| match c {
6            '0' => '0',
7            '1' => '1',
8            '2' => '2',
9            '3' => '3',
10            '4' => '4',
11            '5' => '5',
12            '6' => '6',
13            '7' => '7',
14            '8' => '8',
15            '9' => '9',
16            _ => c,
17        })
18        .collect()
19}
20
21#[cfg(test)]
22mod tests {
23    use crate::formatter::fullwidth_character::format_fullwidth_numerals;
24
25    #[test]
26    fn 全角文字を含む() {
27        assert_eq!(format_fullwidth_numerals("京橋1丁目"), "京橋1丁目");
28        assert_eq!(
29            format_fullwidth_numerals("京橋3丁目1の1"),
30            "京橋3丁目1の1"
31        );
32    }
33}