|
4 | 4 |
|
5 | 5 | use crate::{ |
6 | 6 | cell_collector::CollectCellsError, |
7 | | - nodes::{root::Root, Node, NodeName}, |
| 7 | + nodes::{root::Root, Node, NodeName, NodeProperty}, |
8 | 8 | parsing::{NoPanic, Parser}, |
9 | 9 | properties::values::{InvalidPropertyValue, U32List}, |
10 | 10 | FdtError, |
@@ -155,26 +155,40 @@ fn print_properties<'a, P: Parser<'a>>( |
155 | 155 | } |
156 | 156 | _ => match prop.as_value::<&str>() { |
157 | 157 | Ok("") => writeln!(f, "{:width$}{};", ' ', prop.name, width = depth * 4 + 4)?, |
158 | | - Ok(value) => writeln!(f, "{:width$}{} = {:?};", ' ', prop.name, value, width = depth * 4 + 4)?, |
159 | | - _ => match prop.value.len() { |
160 | | - 0 => writeln!(f, "{:width$}{};", ' ', prop.name, width = depth * 4 + 4)?, |
161 | | - _ => { |
162 | | - write!(f, "{:width$}{} = <", ' ', prop.name, width = depth * 4 + 4)?; |
| 158 | + Ok(value) => { |
| 159 | + let len = value.len(); |
| 160 | + let printable_character_count = value.chars().filter(|c| c.is_ascii_graphic()).count(); |
163 | 161 |
|
164 | | - for (i, n) in prop.as_value::<U32List>()?.iter().enumerate() { |
165 | | - if i != 0 { |
166 | | - write!(f, " ")?; |
167 | | - } |
168 | | - |
169 | | - write!(f, "{n:#04x}")?; |
170 | | - } |
171 | | - |
172 | | - writeln!(f, ">;")?; |
| 162 | + match printable_character_count * 100 / len { |
| 163 | + 0..75 => print_prop_raw_value(f, prop, depth)?, |
| 164 | + _ => writeln!(f, "{:width$}{} = {:?};", ' ', prop.name, value, width = depth * 4 + 4)?, |
173 | 165 | } |
174 | | - }, |
| 166 | + } |
| 167 | + _ => print_prop_raw_value(f, prop, depth)?, |
175 | 168 | }, |
176 | 169 | } |
177 | 170 | } |
178 | 171 |
|
179 | 172 | Ok(any_props) |
180 | 173 | } |
| 174 | + |
| 175 | +fn print_prop_raw_value(f: &mut core::fmt::Formatter<'_>, prop: NodeProperty<'_>, depth: usize) -> Result<(), Error> { |
| 176 | + match prop.value.len() { |
| 177 | + 0 => writeln!(f, "{:width$}{};", ' ', prop.name, width = depth * 4 + 4)?, |
| 178 | + _ => { |
| 179 | + write!(f, "{:width$}{} = <", ' ', prop.name, width = depth * 4 + 4)?; |
| 180 | + |
| 181 | + for (i, n) in prop.as_value::<U32List>()?.iter().enumerate() { |
| 182 | + if i != 0 { |
| 183 | + write!(f, " ")?; |
| 184 | + } |
| 185 | + |
| 186 | + write!(f, "{n:#04x}")?; |
| 187 | + } |
| 188 | + |
| 189 | + writeln!(f, ">;")?; |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + Ok(()) |
| 194 | +} |
0 commit comments