diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2020-11-17 15:48:33 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2020-11-19 14:55:14 -0800 |
commit | 0fb0c3759a04c025800e3175fb4cbd8d595f8c4b (patch) | |
tree | 974a522ed63edb715fd0090a9bad1f3f03cfaf0a /rust/src/identifiers.rs | |
parent | 89016d99a20269c1a576bd4c7673f83af55e8218 (diff) | |
download | fatcat-0fb0c3759a04c025800e3175fb4cbd8d595f8c4b.tar.gz fatcat-0fb0c3759a04c025800e3175fb4cbd8d595f8c4b.zip |
rust: fatcatd changes for DOAJ+dblp identifiers
Diffstat (limited to 'rust/src/identifiers.rs')
-rw-r--r-- | rust/src/identifiers.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/rust/src/identifiers.rs b/rust/src/identifiers.rs index 180dc43b..22ffcc79 100644 --- a/rust/src/identifiers.rs +++ b/rust/src/identifiers.rs @@ -362,6 +362,55 @@ fn test_check_isbn13() { assert!(check_isbn13("9781566199094").is_err()); } +pub fn check_doaj_id(raw: &str) -> Result<()> { + lazy_static! { + static ref RE: Regex = Regex::new(r"^[a-f0-9]{32}$").unwrap(); + } + if raw.is_ascii() && RE.is_match(raw) { + Ok(()) + } else { + Err(FatcatError::MalformedChecksum( + "DOAJ Article Identifier (expected, eg, 'e58f08a11ecb495ead55a44ad4f89808')" + .to_string(), + raw.to_string(), + ))? + } +} + +#[test] +fn test_check_doaj_id() { + assert!(check_doaj_id("e58f08a11ecb495ead55a44ad4f89808").is_ok()); + assert!(check_doaj_id("1b39813549077b2347c0f370c3864b40").is_ok()); + assert!(check_doaj_id("1b39813549077b2347c0f370c3864b40 ").is_err()); + assert!(check_doaj_id("1g39813549077b2347c0f370c3864b40").is_err()); + assert!(check_doaj_id("1B39813549077B2347C0F370c3864b40").is_err()); + assert!(check_doaj_id("1b39813549077b2347c0f370c3864b4").is_err()); + assert!(check_doaj_id("1b39813549077b2347c0f370c3864b411").is_err()); +} + +pub fn check_dblp_id(raw: &str) -> Result<()> { + lazy_static! { + // TODO: what should this actually be? more or less restrictive? + static ref RE: Regex = Regex::new(r"^[a-z]+/[a-zA-Z0-9]+/[a-zA-Z0-9/]+$").unwrap(); + } + if raw.is_ascii() && RE.is_match(raw) { + Ok(()) + } else { + Err(FatcatError::MalformedChecksum( + "dblp Article Key (expected, eg, 'journals/entcs/GoubaultM12')".to_string(), + raw.to_string(), + ))? + } +} + +#[test] +fn test_check_dblp_id() { + assert!(check_dblp_id("journals/entcs/GoubaultM12").is_ok()); + assert!(check_dblp_id("journals/entcs/GoubaultM12").is_ok()); + assert!(check_dblp_id("10.123*").is_err()); + assert!(check_dblp_id("").is_err()); +} + pub fn check_issn(raw: &str) -> Result<()> { lazy_static! { static ref RE: Regex = Regex::new(r"^\d{4}-\d{3}[0-9X]$").unwrap(); |