@@ -70,6 +70,19 @@ pub struct AmbiguityChanges {
70
70
pub changes : BTreeMap < OwnedRoomId , BTreeMap < OwnedEventId , AmbiguityChange > > ,
71
71
}
72
72
73
+ static MXID_REGEX : Lazy < Regex > = Lazy :: new ( || {
74
+ Regex :: new ( DisplayName :: MXID_PATTERN )
75
+ . expect ( "We should be able to create a regex from our static MXID pattern" )
76
+ } ) ;
77
+ static LEFT_TO_RIGHT_REGEX : Lazy < Regex > = Lazy :: new ( || {
78
+ Regex :: new ( DisplayName :: LEFT_TO_RIGHT_PATTERN )
79
+ . expect ( "We should be able to create a regex from our static left-to-right pattern" )
80
+ } ) ;
81
+ static HIDDEN_CHARACTERS_REGEX : Lazy < Regex > = Lazy :: new ( || {
82
+ Regex :: new ( DisplayName :: HIDDEN_CHARACTERS_PATTERN )
83
+ . expect ( "We should be able to create a regex from our static hidden characters pattern" )
84
+ } ) ;
85
+
73
86
/// A high-level wrapper for strings representing display names.
74
87
///
75
88
/// This wrapper provides attempts to determine whether a display name
@@ -145,19 +158,6 @@ impl DisplayName {
145
158
const HIDDEN_CHARACTERS_PATTERN : & str =
146
159
"[\u{2000} -\u{200D} \u{300} -\u{036f} \u{2062} -\u{2063} \u{2800} \u{061c} \u{feff} ]" ;
147
160
148
- const MXID_REGEX : Lazy < Regex > = Lazy :: new ( || {
149
- Regex :: new ( DisplayName :: MXID_PATTERN )
150
- . expect ( "We should be able to create a regex from our static MXID pattern" )
151
- } ) ;
152
- const LEFT_TO_RIGHT_REGEX : Lazy < Regex > = Lazy :: new ( || {
153
- Regex :: new ( DisplayName :: LEFT_TO_RIGHT_PATTERN )
154
- . expect ( "We should be able to create a regex from our static left-to-right pattern" )
155
- } ) ;
156
- const HIDDEN_CHARACTERS_REGEX : Lazy < Regex > = Lazy :: new ( || {
157
- Regex :: new ( DisplayName :: HIDDEN_CHARACTERS_PATTERN )
158
- . expect ( "We should be able to create a regex from our static hidden characters pattern" )
159
- } ) ;
160
-
161
161
/// Creates a new [`DisplayName`] from the given raw string.
162
162
///
163
163
/// The raw display name is transformed into a Unicode-normalized form, with
@@ -169,11 +169,11 @@ impl DisplayName {
169
169
/// during construction.
170
170
pub fn new ( raw : & str ) -> Self {
171
171
let normalized = raw. nfd ( ) . collect :: < String > ( ) ;
172
- let replaced = Self :: HIDDEN_CHARACTERS_REGEX . replace_all ( & normalized, "" ) ;
172
+ let replaced = HIDDEN_CHARACTERS_REGEX . replace_all ( & normalized, "" ) ;
173
173
174
174
let decancered = decancer:: cure!( & replaced)
175
175
. ok ( )
176
- . map ( |cured| Self :: LEFT_TO_RIGHT_REGEX . replace_all ( cured. as_ref ( ) , "" ) . to_string ( ) ) ;
176
+ . map ( |cured| LEFT_TO_RIGHT_REGEX . replace_all ( cured. as_ref ( ) , "" ) . to_string ( ) ) ;
177
177
178
178
Self { raw : raw. to_owned ( ) , decancered }
179
179
}
@@ -226,11 +226,11 @@ impl DisplayName {
226
226
}
227
227
228
228
fn has_left_to_right_characters ( & self ) -> bool {
229
- Self :: LEFT_TO_RIGHT_REGEX . is_match ( & self . raw )
229
+ LEFT_TO_RIGHT_REGEX . is_match ( & self . raw )
230
230
}
231
231
232
232
fn might_look_like_an_mxid ( & self ) -> bool {
233
- Self :: MXID_REGEX . is_match ( & self . raw )
233
+ MXID_REGEX . is_match ( & self . raw )
234
234
}
235
235
}
236
236
0 commit comments