edf_rs/utils.rs
1pub(crate) fn take_vec<T>(vec: &mut Vec<T>) -> Vec<T> {
2 std::mem::take(vec)
3}
4
5pub(crate) fn serialize_field(value: Option<String>) -> String {
6 value.map(|v| v.replace(" ", "_")).unwrap_or("X".to_string())
7}
8
9pub(crate) fn deserialize_field(value: &str) -> Option<String> {
10 if value == "X" {
11 return None;
12 }
13
14 // TODO: Add serializer option to replace `_` with ` ` automatically
15 Some(value.replace("_", " "))
16}
17
18pub(crate) fn is_printable_ascii(s: &str) -> bool {
19 s.bytes().all(|b| matches!(b, 0x20..=0x7E))
20}