Skip to content

Commit

Permalink
skip short numeric IDs instead of error
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesamcl committed Sep 11, 2024
1 parent b848933 commit be7dfc3
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions 02_assign_ids/grebi_extract_identifiers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,30 @@ fn main() {
json.begin_array();
while json.peek().kind != JsonTokenType::EndArray {
if json.peek().kind == JsonTokenType::StartString {
if wrote_any {
writer.write_all(b"\t").unwrap();
} else {
wrote_any = true;
}
let id = json.string();
check_id(&k, &id);
writer.write_all(&id).unwrap();
if check_id(&k, &id) {
if wrote_any {
writer.write_all(b"\t").unwrap();
} else {
wrote_any = true;
}
writer.write_all(&id).unwrap();
}
} else {
json.value(); // skip
}
}
json.end_array();
} else if json.peek().kind == JsonTokenType::StartString {
if wrote_any {
writer.write_all(b"\t").unwrap();
} else {
wrote_any = true;
}
let id = json.string();
check_id(&k, &id);
writer.write_all(&id).unwrap();
if check_id(&k, &id) {
if wrote_any {
writer.write_all(b"\t").unwrap();
} else {
wrote_any = true;
}
writer.write_all(&id).unwrap();
}
} else {
json.value(); // skip
}
Expand All @@ -114,21 +116,19 @@ fn main() {

}

fn check_id(k:&[u8], id:&[u8]) {
fn check_id(k:&[u8], id:&[u8]) -> bool {
if id.len() >= 16 {
// long numeric ID is prob a UUID and fine
return;
return true;
}
let mut has_non_numeric = false;
for c in id {
if !c.is_ascii_digit() {
has_non_numeric = true;
break;
return true;
}
}
if !has_non_numeric {
panic!("Found unprefixed numeric ID {} for identifier property {}. Unqualified numbers like this as identifiers are ambiguous and may cause incorrect equivalences.", String::from_utf8_lossy(id), String::from_utf8_lossy(k));
}
// also triggers for blank IDs
eprintln!("Found unprefixed numeric ID {} for identifier property {}. Unqualified numbers like this as identifiers are ambiguous and may cause incorrect equivalences.", String::from_utf8_lossy(id), String::from_utf8_lossy(k));
return false;
}


Expand Down

0 comments on commit be7dfc3

Please sign in to comment.