For content titles:
- remove everything that is not alphanumeric, - or ' - replace : with - - replace multiple whitespaces with one
This commit is contained in:
parent
3f6596bbfd
commit
d2948c9c4d
5 changed files with 112 additions and 6 deletions
|
@ -6,6 +6,7 @@ extern crate curl;
|
|||
extern crate env_logger;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate regex;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
#[macro_use]
|
||||
|
@ -28,7 +29,7 @@ fn main() {
|
|||
env_logger::init().unwrap();
|
||||
|
||||
let matches = App::new("Gog Synchronizer")
|
||||
.version("0.3.2")
|
||||
.version("0.3.3")
|
||||
.author("Sebastian Hugentobler <sebastian@vanwa.ch>")
|
||||
.about("Synchronizes your gog library to a local folder.")
|
||||
.arg(Arg::with_name("game-storage")
|
||||
|
|
|
@ -4,6 +4,8 @@ use std::hash::{Hash, Hasher};
|
|||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Token {
|
||||
|
@ -73,6 +75,7 @@ impl Config {
|
|||
pub struct Content {
|
||||
#[serde(skip_deserializing)]
|
||||
pub id: u64,
|
||||
#[serde(deserialize_with = "normalize_title")]
|
||||
pub title: String,
|
||||
#[serde(skip_deserializing)]
|
||||
#[serde(rename(deserialize = "cdKey"))]
|
||||
|
@ -90,6 +93,25 @@ impl fmt::Display for Content {
|
|||
}
|
||||
}
|
||||
|
||||
fn normalize_title<D>(deserializer: D) -> Result<String, D::Error>
|
||||
where D: Deserializer
|
||||
{
|
||||
let raw_title = String::deserialize(deserializer)?.replace(":", " - ");
|
||||
|
||||
let regex_normalize = Regex::new(r"[^'^\w^\s^-]+").unwrap();
|
||||
let regex_whitespace = Regex::new(r"\s\s+").unwrap();
|
||||
|
||||
let title_normalized = regex_normalize
|
||||
.replace_all(raw_title.as_str(), "")
|
||||
.to_string();
|
||||
|
||||
let title_whitespace = regex_whitespace
|
||||
.replace_all(title_normalized.as_str(), " ")
|
||||
.to_string();
|
||||
|
||||
Ok(title_whitespace)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ContentInfo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue