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