govis

package
Version: v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: BSD-3-Clause, Apache-2.0 Imports: 3 Imported by: 1

README

govis

govis is a BSD-compatible vis(3) and unvis(3) encoding implementation that is unicode aware and written in Go. None of this code comes from the original BSD code, nor does it come from go-mtree's port of said code. Because 80s BSD code is not very nice to read.

License

govis is licensed under the Apache 2.0 license.

govis: unicode aware vis(3) encoding implementation
Copyright (C) 2017 SUSE LLC.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL