Skip to content

Commit

Permalink
fix: do not attempt to decode utf8
Browse files Browse the repository at this point in the history
native xxd doesn't try to either
  • Loading branch information
felixge committed Jan 11, 2015
1 parent 90262b3 commit e9ebeb0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions xxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os"
"unicode/utf8"
)

func main() {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit e9ebeb0

Please sign in to comment.