From 1391e09234529a9f3cd9b51fa48bc3ebac31b02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 19 Nov 2024 09:52:38 +0100 Subject: [PATCH] fixup! feat(base): Introduce a DisplayName struct --- .../src/deserialized_responses.rs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-base/src/deserialized_responses.rs b/crates/matrix-sdk-base/src/deserialized_responses.rs index dac6d250ec..b8f0f81701 100644 --- a/crates/matrix-sdk-base/src/deserialized_responses.rs +++ b/crates/matrix-sdk-base/src/deserialized_responses.rs @@ -82,13 +82,27 @@ static HIDDEN_CHARACTERS_REGEX: Lazy = Lazy::new(|| { Regex::new(DisplayName::HIDDEN_CHARACTERS_PATTERN) .expect("We should be able to create a regex from our static hidden characters pattern") }); + +/// Regex to match `i` characters. +/// +/// This is used to replace an `i` with a lowercase `l`, i.e. to mark "Hello" +/// and "HeIlo" as ambiguous. Decancer will lowercase an `I` for us. static I_REGEX: Lazy = Lazy::new(|| { - Regex::new(DisplayName::I_PATTERN) - .expect("We should be able to create a regex from our uppercase I pattern") + Regex::new("[i]").expect("We should be able to create a regex from our uppercase I pattern") }); + +/// Regex to match `0` characters. +/// +/// This is used to replace an `0` with a lowercase `o`, i.e. to mark "HellO" +/// and "Hell0" as ambiguous. Decancer will lowercase an `O` for us. static ZERO_REGEX: Lazy = Lazy::new(|| { Regex::new("[0]").expect("We should be able to create a regex from our zero pattern") }); + +/// Regex to match a couple of dot-like characters, also matches an actual dot. +/// +/// This is used to replace a `.` with a `:`, i.e. to mark "@mxid.domain.tld" as +/// ambiguous. static DOT_REGEX: Lazy = Lazy::new(|| { Regex::new("[.\u{1d16d}]").expect("We should be able to create a regex from our dot pattern") }); @@ -165,12 +179,6 @@ impl DisplayName { const HIDDEN_CHARACTERS_PATTERN: &str = "[\u{2000}-\u{200D}\u{300}-\u{036f}\u{2062}-\u{2063}\u{2800}\u{061c}\u{feff}]"; - /// Regex pattern to match `i` characters (upper and lower case). - /// - /// This is used to replace an uppercase I with a lowercase l, i.e. to mark - /// "Hello" and "HeIlo" as ambiguous. - const I_PATTERN: &str = "[Ii]"; - /// Creates a new [`DisplayName`] from the given raw string. /// /// The raw display name is transformed into a Unicode-normalized form, with