From e9ebeb0abdf78f6e7729fdbfc68842b3a86ee0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 11 Jan 2015 16:24:25 +0100 Subject: [PATCH] fix: do not attempt to decode utf8 native xxd doesn't try to either --- xxd.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/xxd.go b/xxd.go index 31fc3d9..6d8e730 100644 --- a/xxd.go +++ b/xxd.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "unicode/utf8" ) func main() { @@ -66,15 +65,12 @@ func XXD(r io.Reader, w io.Writer) error { // Character values b := buf[:n] - for len(b) > 0 { - r, size := utf8.DecodeRune(b) - - if int(r) > 0x1f && int(r) < 0x7f { - fmt.Fprintf(w, "%v", string(r)) + for _, c := range b { + if c > 0x1f && c < 0x7f { + fmt.Fprintf(w, "%v", string(c)) } else { fmt.Fprintf(w, ".") } - b = b[size:] } fmt.Fprintf(w, "\n")