Skip to content

Commit

Permalink
#292: Normalize apostrophes and quotation marks in titles
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed May 17, 2024
1 parent 5dc44ae commit 55a21f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions src/scan/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ static RE_EDITION_KNOWN: Lazy<Regex> = 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<Regex> = Lazy::new(|| Regex::new(r#" [^ ]+ edition$"#).unwrap());
static RE_YEAR_SUFFIX: Lazy<Regex> = Lazy::new(|| Regex::new(r" \(\d+\)$").unwrap());
static RE_SYMBOLS: Lazy<Regex> = Lazy::new(|| Regex::new(r#"[™®©:-]"#).unwrap());
static RE_SYMBOLS_GAP: Lazy<Regex> = Lazy::new(|| Regex::new(r#"[™®©:-]"#).unwrap());
static RE_SYMBOLS_NO_GAP: Lazy<Regex> = Lazy::new(|| Regex::new(r#"['"‘’“”]"#).unwrap());
static RE_SPACES: Lazy<Regex> = Lazy::new(|| Regex::new(r#" {2,}"#).unwrap());

pub fn normalize_title(title: &str) -> String {
Expand All @@ -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()
}
Expand Down Expand Up @@ -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 "));
Expand Down

0 comments on commit 55a21f3

Please # to comment.