Skip to content

Instantly share code, notes, and snippets.

@x1unix
Created December 16, 2023 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x1unix/000fadc38ab6b0ff907a4789eb3b01b1 to your computer and use it in GitHub Desktop.
Save x1unix/000fadc38ab6b0ff907a4789eb3b01b1 to your computer and use it in GitHub Desktop.
strdump
package main
import (
"bufio"
"fmt"
"io"
"os"
_ "unsafe"
)
//go:linkname appendEscapedRune strconv.appendEscapedRune
func appendEscapedRune(buf []byte, r rune, quote byte, ASCIIonly, graphicOnly bool) []byte
func main() {
buff := make([]byte, 0, 8)
defer fmt.Print("\n")
r := bufio.NewReader(os.Stdin)
for {
c, err := r.ReadByte()
if err != nil {
if err == io.EOF {
return
}
fmt.Fprintln(os.Stderr, "reading standard input:", err)
os.Exit(1)
}
// Reset buffer and quote rune
buff = buff[:0]
buff = appendEscapedRune(buff, rune(c), 0, false, false)
_, _ = os.Stdout.Write(buff)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment