diff --git a/CHANGELOG.md b/CHANGELOG.md index fe75aa0..94fbd65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ * Added: * Support for Amazon/sideloaded games in Heroic. +* Changed: + * Title normalization now ignores apostrophes and quotation marks + (e.g., `ludusavi find --normalized "Mirrors Edge"` will find `Mirror's Edge`). ## v0.23.0 (2024-04-27) diff --git a/src/scan/title.rs b/src/scan/title.rs index 95dad24..374069c 100644 --- a/src/scan/title.rs +++ b/src/scan/title.rs @@ -13,7 +13,8 @@ static RE_EDITION_KNOWN: Lazy = Lazy::new(|| Regex::new(r#" (game of the /// We can't assume more than one word because it may be part of the main title. static RE_EDITION_SHORT: Lazy = Lazy::new(|| Regex::new(r#" [^ ]+ edition$"#).unwrap()); static RE_YEAR_SUFFIX: Lazy = Lazy::new(|| Regex::new(r" \(\d+\)$").unwrap()); -static RE_SYMBOLS: Lazy = Lazy::new(|| Regex::new(r#"[™®©:-]"#).unwrap()); +static RE_SYMBOLS_GAP: Lazy = Lazy::new(|| Regex::new(r#"[™®©:-]"#).unwrap()); +static RE_SYMBOLS_NO_GAP: Lazy = Lazy::new(|| Regex::new(r#"['"‘’“”]"#).unwrap()); static RE_SPACES: Lazy = Lazy::new(|| Regex::new(r#" {2,}"#).unwrap()); pub fn normalize_title(title: &str) -> String { @@ -22,7 +23,8 @@ pub fn normalize_title(title: &str) -> String { let normalized = RE_EDITION_PUNCTUATED.replace_all(&normalized, ""); let normalized = RE_EDITION_KNOWN.replace_all(&normalized, ""); let normalized = RE_EDITION_SHORT.replace_all(&normalized, ""); - let normalized = RE_SYMBOLS.replace_all(&normalized, " "); + let normalized = RE_SYMBOLS_GAP.replace_all(&normalized, " "); + let normalized = RE_SYMBOLS_NO_GAP.replace_all(&normalized, ""); let normalized = RE_SPACES.replace_all(&normalized, " "); normalized.trim().to_string() } @@ -285,6 +287,8 @@ mod tests { // symbols assert_eq!("foo bar", normalize_title("Foo:Bar")); assert_eq!("foo bar", normalize_title("Foo: Bar")); + assert_eq!("foo bar", normalize_title("Fo'o Bar")); + assert_eq!("foo bar", normalize_title("Foo \"Bar\"")); // spaces assert_eq!("foo bar", normalize_title(" Foo Bar "));