summaryrefslogtreecommitdiffstats
path: root/rust/src/identifiers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/identifiers.rs')
-rw-r--r--rust/src/identifiers.rs49
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();