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