sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

Simplify check for "ByteCategory::AsciiPrintable" #78

Closed rendner closed 4 years ago

rendner commented 4 years ago

https://github.com/sharkdp/hexyl/blob/67b6c2533d47af6547894b04263243fbff9661a2/src/lib.rs#L38-L40

I guess that can be simplified to just look for is_ascii_graphic:

else if  self.0.is_ascii_graphic()

I would also prefer to change the name of the variable "AsciiPrintable", because "printable" normally also includes the space.

sharkdp commented 4 years ago

sounds good, if this is really the same.

rendner commented 4 years ago

As you can see the range of ASCII characters which have a graphical representation also includes the values of the other two groups:

https://doc.rust-lang.org/std/primitive.char.html#method.is_ascii_graphic

Checks if the value is an ASCII graphic character: U+0021 '!' ..= U+007E '~'.

https://doc.rust-lang.org/std/primitive.char.html#method.is_ascii_alphanumeric

Checks if the value is an ASCII alphanumeric character: U+0041 'A' ..= U+005A 'Z', or U+0061 'a' ..= U+007A 'z', or U+0030 '0' ..= U+0039 '9'.

https://doc.rust-lang.org/std/primitive.char.html#method.is_ascii_punctuation

Checks if the value is an ASCII punctuation character: U+0021 ..= U+002F ! " # $ % & ' ( ) * + , - . /, or U+003A ..= U+0040 : ; < = > ? @, or U+005B ..= U+0060 [ \ ] ^ _ ` , or U+007B ..= U+007E { | } ~

sharkdp commented 4 years ago

Okay, thanks :smile: Let's change this.