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 OpenSingle,
85 SinglePrime,
87 DoublePrime,
89 Backtick,
91}
92
93impl Punctuation {
94 pub fn from_char(c: char) -> Option<Punctuation> {
95 let punct = match c {
96 '´' => Punctuation::Acute,
97 '&' => Punctuation::Ampersand,
98 '’' => Punctuation::Apostrophe,
99 '\'' => Punctuation::Apostrophe,
100 '@' => Punctuation::At,
101 '\\' => Punctuation::Backslash,
102 '!' => Punctuation::Bang,
103 '^' => Punctuation::Caret,
104 ':' => Punctuation::Colon,
105 ',' => Punctuation::Comma,
106 '、' => Punctuation::Comma,
107 ',' => Punctuation::Comma,
108 '°' => Punctuation::Degree,
109 '″' => Punctuation::DoublePrime,
110 '–' => Punctuation::EnDash,
111 '—' => Punctuation::EmDash,
112 '…' => Punctuation::Ellipsis,
113 '=' => Punctuation::Equal,
114 '/' => Punctuation::ForwardSlash,
115 '>' => Punctuation::GreaterThan,
116 '#' => Punctuation::Hash,
117 '-' => Punctuation::Hyphen,
118 '<' => Punctuation::LessThan,
119 '‘' => Punctuation::OpenSingle,
120 '%' => Punctuation::Percent,
121 '|' => Punctuation::Pipe,
122 '+' => Punctuation::Plus,
123 '?' => Punctuation::Question,
124 '.' => Punctuation::Period,
125 ';' => Punctuation::Semicolon,
126 '′' => Punctuation::SinglePrime,
127 '*' => Punctuation::Star,
128 '~' => Punctuation::Tilde,
129 '_' => Punctuation::Underscore,
130
131 '[' => Punctuation::OpenSquare,
132 ']' => Punctuation::CloseSquare,
133 '{' => Punctuation::OpenCurly,
134 '}' => Punctuation::CloseCurly,
135 '(' => Punctuation::OpenRound,
136 ')' => Punctuation::CloseRound,
137 '`' => Punctuation::Backtick,
138 _ => Punctuation::Currency(Currency::from_char(c)?),
139 };
140
141 Some(punct)
142 }
143}
144
145#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Hash)]
146pub struct Quote {
147 pub twin_loc: Option<usize>,
149}