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