Skip to content

Commit 1391e09

Browse files
committed
fixup! feat(base): Introduce a DisplayName struct
1 parent 62c7405 commit 1391e09

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

crates/matrix-sdk-base/src/deserialized_responses.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,27 @@ static HIDDEN_CHARACTERS_REGEX: Lazy<Regex> = Lazy::new(|| {
8282
Regex::new(DisplayName::HIDDEN_CHARACTERS_PATTERN)
8383
.expect("We should be able to create a regex from our static hidden characters pattern")
8484
});
85+
86+
/// Regex to match `i` characters.
87+
///
88+
/// This is used to replace an `i` with a lowercase `l`, i.e. to mark "Hello"
89+
/// and "HeIlo" as ambiguous. Decancer will lowercase an `I` for us.
8590
static I_REGEX: Lazy<Regex> = Lazy::new(|| {
86-
Regex::new(DisplayName::I_PATTERN)
87-
.expect("We should be able to create a regex from our uppercase I pattern")
91+
Regex::new("[i]").expect("We should be able to create a regex from our uppercase I pattern")
8892
});
93+
94+
/// Regex to match `0` characters.
95+
///
96+
/// This is used to replace an `0` with a lowercase `o`, i.e. to mark "HellO"
97+
/// and "Hell0" as ambiguous. Decancer will lowercase an `O` for us.
8998
static ZERO_REGEX: Lazy<Regex> = Lazy::new(|| {
9099
Regex::new("[0]").expect("We should be able to create a regex from our zero pattern")
91100
});
101+
102+
/// Regex to match a couple of dot-like characters, also matches an actual dot.
103+
///
104+
/// This is used to replace a `.` with a `:`, i.e. to mark "@mxid.domain.tld" as
105+
/// ambiguous.
92106
static DOT_REGEX: Lazy<Regex> = Lazy::new(|| {
93107
Regex::new("[.\u{1d16d}]").expect("We should be able to create a regex from our dot pattern")
94108
});
@@ -165,12 +179,6 @@ impl DisplayName {
165179
const HIDDEN_CHARACTERS_PATTERN: &str =
166180
"[\u{2000}-\u{200D}\u{300}-\u{036f}\u{2062}-\u{2063}\u{2800}\u{061c}\u{feff}]";
167181

168-
/// Regex pattern to match `i` characters (upper and lower case).
169-
///
170-
/// This is used to replace an uppercase I with a lowercase l, i.e. to mark
171-
/// "Hello" and "HeIlo" as ambiguous.
172-
const I_PATTERN: &str = "[Ii]";
173-
174182
/// Creates a new [`DisplayName`] from the given raw string.
175183
///
176184
/// The raw display name is transformed into a Unicode-normalized form, with

0 commit comments

Comments
 (0)