From 8213da020e943257bb1ffdf41320b88d5bec7841 Mon Sep 17 00:00:00 2001 From: arty Date: Tue, 26 Mar 2024 22:54:49 -0700 Subject: [PATCH] Make printable set exactly the same so we choose precisely the same disassembled representation in all cases --- resources/tests/test_binutils_api.py | 3 ++- src/classic/clvm_tools/binutils.rs | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/resources/tests/test_binutils_api.py b/resources/tests/test_binutils_api.py index 7dc384e96..1c237785f 100644 --- a/resources/tests/test_binutils_api.py +++ b/resources/tests/test_binutils_api.py @@ -12,7 +12,8 @@ "(1 2 3)", "((4 5 6) (7 8 9))", "(i (q . 1) (q . 2) (q . 3))", - "((0x33 . i))" + "((0x33 . i))", + "(g . (138935604050210 ()))" ] def extend_atom(): diff --git a/src/classic/clvm_tools/binutils.rs b/src/classic/clvm_tools/binutils.rs index 505123057..0ebe3a4ca 100644 --- a/src/classic/clvm_tools/binutils.rs +++ b/src/classic/clvm_tools/binutils.rs @@ -1,4 +1,5 @@ use std::borrow::Borrow; +use std::collections::HashSet; use std::rc::Rc; use encoding8::ascii::is_printable; @@ -14,15 +15,12 @@ use crate::classic::clvm_tools::ir::r#type::IRRepr; use crate::classic::clvm_tools::ir::reader::IRReader; use crate::classic::clvm_tools::ir::writer::write_ir; +lazy_static! { + pub static ref printable_chars: HashSet = + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ".chars().collect(); +} pub fn is_printable_string(s: &str) -> bool { - for ch in s.graphemes(true) { - if ch.chars().next().unwrap() > 0xff as char - || !is_printable(ch.chars().next().unwrap() as u8) - { - return false; - } - } - true + s.chars().all(|s_char| printable_chars.contains(&s_char)) } pub fn assemble_from_ir(