Skip to content

Commit be7dfc3

Browse files
committed
skip short numeric IDs instead of error
1 parent b848933 commit be7dfc3

File tree

1 file changed

+22
-22
lines changed
  • 02_assign_ids/grebi_extract_identifiers/src

1 file changed

+22
-22
lines changed

02_assign_ids/grebi_extract_identifiers/src/main.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,30 @@ fn main() {
7171
json.begin_array();
7272
while json.peek().kind != JsonTokenType::EndArray {
7373
if json.peek().kind == JsonTokenType::StartString {
74-
if wrote_any {
75-
writer.write_all(b"\t").unwrap();
76-
} else {
77-
wrote_any = true;
78-
}
7974
let id = json.string();
80-
check_id(&k, &id);
81-
writer.write_all(&id).unwrap();
75+
if check_id(&k, &id) {
76+
if wrote_any {
77+
writer.write_all(b"\t").unwrap();
78+
} else {
79+
wrote_any = true;
80+
}
81+
writer.write_all(&id).unwrap();
82+
}
8283
} else {
8384
json.value(); // skip
8485
}
8586
}
8687
json.end_array();
8788
} else if json.peek().kind == JsonTokenType::StartString {
88-
if wrote_any {
89-
writer.write_all(b"\t").unwrap();
90-
} else {
91-
wrote_any = true;
92-
}
9389
let id = json.string();
94-
check_id(&k, &id);
95-
writer.write_all(&id).unwrap();
90+
if check_id(&k, &id) {
91+
if wrote_any {
92+
writer.write_all(b"\t").unwrap();
93+
} else {
94+
wrote_any = true;
95+
}
96+
writer.write_all(&id).unwrap();
97+
}
9698
} else {
9799
json.value(); // skip
98100
}
@@ -114,21 +116,19 @@ fn main() {
114116

115117
}
116118

117-
fn check_id(k:&[u8], id:&[u8]) {
119+
fn check_id(k:&[u8], id:&[u8]) -> bool {
118120
if id.len() >= 16 {
119121
// long numeric ID is prob a UUID and fine
120-
return;
122+
return true;
121123
}
122-
let mut has_non_numeric = false;
123124
for c in id {
124125
if !c.is_ascii_digit() {
125-
has_non_numeric = true;
126-
break;
126+
return true;
127127
}
128128
}
129-
if !has_non_numeric {
130-
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));
131-
}
129+
// also triggers for blank IDs
130+
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));
131+
return false;
132132
}
133133

134134

0 commit comments

Comments
 (0)