package govis

import "github.com/vbatts/go-mtree/pkg/govis"

Index

Functions

func Unvis

func Unvis(input string, flag VisFlag) (string, error)

Unvis takes a string formatted with the given Vis flags (though only the VisHTTPStyle flag is checked) and output the un-encoded version of the encoded string. An error is returned if any escape sequences in the input string were invalid.

func Vis

func Vis(src string, flag VisFlag) (string, error)

Vis encodes the provided string to a BSD-compatible encoding using BSD's vis() flags. However, it will correctly handle multi-byte encoding (which is not done properly by BSD's vis implementation).

Types

type VisFlag

type VisFlag uint

VisFlag manipulates how the characters are encoded/decoded

const (
	VisOctal     VisFlag = (1 << iota) // VIS_OCTAL: Use octal \ddd format.
	VisCStyle                          // VIS_CSTYLE: Use \[nrft0..] where appropriate.
	VisSpace                           // VIS_SP: Also encode space.
	VisTab                             // VIS_TAB: Also encode tab.
	VisNewline                         // VIS_NL: Also encode newline.
	VisSafe                            // VIS_SAFE: Encode unsafe characters.
	VisNoSlash                         // VIS_NOSLASH: Inhibit printing '\'.
	VisHTTPStyle                       // VIS_HTTPSTYLE: HTTP-style escape %xx.
	VisGlob                            // VIS_GLOB: Encode glob(3) magics.

	VisWhite VisFlag = (VisSpace | VisTab | VisNewline)
)

vis() has a variety of flags when deciding what encodings to use. While mtree only uses one set of flags, implementing them all is necessary in order to have compatibility with BSD's vis() and unvis() commands.

Source Files

govis.go unvis.go vis.go

Version
v0.5.4 (latest)
Published
Jun 11, 2024
Platform
js/wasm
Imports
3 packages
Last checked
1 day ago

Tools for package owners.