Skip to content

Commit

Permalink
fixup! feat(base): Introduce a DisplayName struct
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Nov 19, 2024
1 parent 62c7405 commit 1391e09
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions crates/matrix-sdk-base/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,27 @@ static HIDDEN_CHARACTERS_REGEX: Lazy<Regex> = 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<Regex> = 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<Regex> = 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<Regex> = Lazy::new(|| {
Regex::new("[.\u{1d16d}]").expect("We should be able to create a regex from our dot pattern")
});
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1391e09

Please sign in to comment.