1use is_macro::Is;
2use serde::{Deserialize, Serialize};
3
4use crate::Currency;
5
6#[derive(
7 Debug, Is, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Default, Hash,
8)]
9#[serde(tag = "kind")]
10pub enum Punctuation {
11 Degree,
13 Ellipsis,
15 EnDash,
17 EmDash,
19 Ampersand,
21 #[default]
23 Period,
24 Bang,
26 Question,
28 Colon,
30 Semicolon,
32 Quote(Quote),
34 Comma,
36 Hyphen,
38 OpenSquare,
40 CloseSquare,
42 OpenRound,
44 CloseRound,
46 OpenCurly,
48 CloseCurly,
50 Hash,
52 Apostrophe,
54 Percent,
56 ForwardSlash,
58 Backslash,
60 LessThan,
62 GreaterThan,
64 Equal,
66 Star,
68 Tilde,
70 At,
72 Caret,
74 Plus,
76 Currency(Currency),
77 Pipe,
79 Underscore,
81 Acute,
83}
84
85impl Punctuation {
86 pub fn from_char(c: char) -> Option<Punctuation> {
87 let punct = match c {
88 '@' => Punctuation::At,
89 '~' => Punctuation::Tilde,
90 '°' => Punctuation::Degree,
91 '=' => Punctuation::Equal,
92 '<' => Punctuation::LessThan,
93 '>' => Punctuation::GreaterThan,
94 '/' => Punctuation::ForwardSlash,
95 '\\' => Punctuation::Backslash,
96 '%' => Punctuation::Percent,
97 '’' => Punctuation::Apostrophe,
98 '\'' => Punctuation::Apostrophe,
99 '.' => Punctuation::Period,
100 '!' => Punctuation::Bang,
101 '?' => Punctuation::Question,
102 ':' => Punctuation::Colon,
103 ';' => Punctuation::Semicolon,
104 ',' => Punctuation::Comma,
105 '、' => Punctuation::Comma,
106 ',' => Punctuation::Comma,
107 '-' => Punctuation::Hyphen,
108 '[' => Punctuation::OpenSquare,
109 ']' => Punctuation::CloseSquare,
110 '{' => Punctuation::OpenCurly,
111 '}' => Punctuation::CloseCurly,
112 '(' => Punctuation::OpenRound,
113 ')' => Punctuation::CloseRound,
114 '#' => Punctuation::Hash,
115 '*' => Punctuation::Star,
116 '&' => Punctuation::Ampersand,
117 '–' => Punctuation::EnDash,
118 '—' => Punctuation::EmDash,
119 '…' => Punctuation::Ellipsis,
120 '^' => Punctuation::Caret,
121 '+' => Punctuation::Plus,
122 '|' => Punctuation::Pipe,
123 '_' => Punctuation::Underscore,
124 '´' => Punctuation::Acute,
125 _ => Punctuation::Currency(Currency::from_char(c)?),
126 };
127
128 Some(punct)
129 }
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Hash)]
133pub struct Quote {
134 pub twin_loc: Option<usize>,
136}