From 9a86d647c520828ba8079870d05f159c1b3e9b52 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sun, 3 Nov 2019 02:02:47 +0100 Subject: Unicode: Hide bytes if there is only one --- src/plugins/unicode.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/unicode.rs b/src/plugins/unicode.rs index 0bb3544..49e4a59 100644 --- a/src/plugins/unicode.rs +++ b/src/plugins/unicode.rs @@ -38,20 +38,26 @@ impl Unicode { let mut buf = [0; 4]; - let byte_string = character + let bytes = character .encode_utf8(&mut buf) .as_bytes() .iter() .map(|b| format!("{:#x}", b)) - .collect::>() - .join(","); + .collect::>(); let name = self.get_name(character); - format!( - "{} is '{}' | UTF-8: {2:#x} ({2}), Bytes: [{3}]", - character, name, character as u32, byte_string - ) + if bytes.len() > 1 { + format!( + "{} is '{}' | UTF-8: {2:#x} ({2}), Bytes: [{3}]", + character, name, character as u32, bytes.join(",") + ) + } else { + format!( + "{} is '{}' | UTF-8: {2:#x} ({2})", + character, name, character as u32 + ) + } } } -- cgit v1.2.3-70-g09d2