@@ -60,54 +60,6 @@ pub enum MathStyle {
60
60
Stretched ,
61
61
}
62
62
63
- impl MathStyle {
64
- /// Applies the style to a given `char`.
65
- ///
66
- /// Note that some styles will convert a character into multiple
67
- /// characters, hence this function always returns an array of two
68
- /// characters.
69
- ///
70
- /// # Examples
71
- ///
72
- /// ```
73
- /// use codex::styling::MathStyle;
74
- ///
75
- /// assert_eq!(['𝑴', '\0'], MathStyle::SerifItalicBold.apply('M'));
76
- /// assert_eq!(['𞸪', '\0'], MathStyle::Initial.apply('ك'));
77
- /// assert_eq!(['ⅈ', '\0'], MathStyle::DoubleStruckItalic.apply('i'));
78
- /// assert_eq!(['𝓴', '\u{fe01}'], MathStyle::RoundhandBold.apply('k'));
79
- /// ```
80
- pub fn apply ( self , c : char ) -> [ char ; 2 ] {
81
- use mappings:: * ;
82
- use MathStyle :: * ;
83
- match self {
84
- Serif => [ to_serif ( c) , '\0' ] ,
85
- SerifBold => [ to_serif_bold ( c) , '\0' ] ,
86
- SerifItalic => [ to_serif_italic ( c) , '\0' ] ,
87
- SerifItalicBold => [ to_serif_italic_bold ( c) , '\0' ] ,
88
- SansSerif => [ to_sans_serif ( c) , '\0' ] ,
89
- SansSerifBold => [ to_sans_serif_bold ( c) , '\0' ] ,
90
- SansSerifItalic => [ to_sans_serif_italic ( c) , '\0' ] ,
91
- SansSerifItalicBold => [ to_sans_serif_italic_bold ( c) , '\0' ] ,
92
- Fraktur => [ to_fraktur ( c) , '\0' ] ,
93
- FrakturBold => [ to_fraktur_bold ( c) , '\0' ] ,
94
- Script => [ to_script ( c) , '\0' ] ,
95
- ScriptBold => [ to_script_bold ( c) , '\0' ] ,
96
- Chancery => to_chancery ( c) ,
97
- ChanceryBold => to_chancery_bold ( c) ,
98
- Roundhand => to_roundhand ( c) ,
99
- RoundhandBold => to_roundhand_bold ( c) ,
100
- DoubleStruck => [ to_double_struck ( c) , '\0' ] ,
101
- DoubleStruckItalic => [ to_double_struck_italic ( c) , '\0' ] ,
102
- Monospace => [ to_monospace ( c) , '\0' ] ,
103
- Initial => [ to_initial ( c) , '\0' ] ,
104
- Tailed => [ to_tailed ( c) , '\0' ] ,
105
- Looped => [ to_looped ( c) , '\0' ] ,
106
- Stretched => [ to_stretched ( c) , '\0' ] ,
107
- }
108
- }
109
- }
110
-
111
63
/// Returns an iterator that yields the styled equivalent of a `char`.
112
64
///
113
65
/// This `struct` is created by the [`to_style`] function. See its
@@ -201,9 +153,35 @@ impl fmt::Display for ToStyle {
201
153
/// .collect::<String>();
202
154
/// assert_eq!("𝕩ℽΩ𝔸𞺸𞺧𝟙⅀𞺮", s);
203
155
/// ```
204
- #[ inline]
205
156
pub fn to_style ( c : char , style : MathStyle ) -> ToStyle {
206
- ToStyle :: new ( style. apply ( c) )
157
+ use mappings:: * ;
158
+ use MathStyle :: * ;
159
+ let styled = match style {
160
+ Serif => [ to_serif ( c) , '\0' ] ,
161
+ SerifBold => [ to_serif_bold ( c) , '\0' ] ,
162
+ SerifItalic => [ to_serif_italic ( c) , '\0' ] ,
163
+ SerifItalicBold => [ to_serif_italic_bold ( c) , '\0' ] ,
164
+ SansSerif => [ to_sans_serif ( c) , '\0' ] ,
165
+ SansSerifBold => [ to_sans_serif_bold ( c) , '\0' ] ,
166
+ SansSerifItalic => [ to_sans_serif_italic ( c) , '\0' ] ,
167
+ SansSerifItalicBold => [ to_sans_serif_italic_bold ( c) , '\0' ] ,
168
+ Fraktur => [ to_fraktur ( c) , '\0' ] ,
169
+ FrakturBold => [ to_fraktur_bold ( c) , '\0' ] ,
170
+ Script => [ to_script ( c) , '\0' ] ,
171
+ ScriptBold => [ to_script_bold ( c) , '\0' ] ,
172
+ Chancery => to_chancery ( c) ,
173
+ ChanceryBold => to_chancery_bold ( c) ,
174
+ Roundhand => to_roundhand ( c) ,
175
+ RoundhandBold => to_roundhand_bold ( c) ,
176
+ DoubleStruck => [ to_double_struck ( c) , '\0' ] ,
177
+ DoubleStruckItalic => [ to_double_struck_italic ( c) , '\0' ] ,
178
+ Monospace => [ to_monospace ( c) , '\0' ] ,
179
+ Initial => [ to_initial ( c) , '\0' ] ,
180
+ Tailed => [ to_tailed ( c) , '\0' ] ,
181
+ Looped => [ to_looped ( c) , '\0' ] ,
182
+ Stretched => [ to_stretched ( c) , '\0' ] ,
183
+ } ;
184
+ ToStyle :: new ( styled)
207
185
}
208
186
209
187
/// Functions which map a `char` to its specified styled form.
0 commit comments