markers

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Start       = '‹'
	StartS      = string(Start)
	StartLen    = len(StartS)
	End         = '›'
	EndS        = string(End)
	EndLen      = len(EndS)
	EscapeMark  = '?'
	EscapeMarkS = string(EscapeMark)
	RedactedS   = StartS + "×" + EndS
)

Internal constants.

Variables

View Source
var (
	StartBytes       = []byte(StartS)
	EndBytes         = []byte(EndS)
	EscapeMarkBytes  = []byte(EscapeMarkS)
	RedactedBytes    = []byte(RedactedS)
	ReStripSensitive = regexp.MustCompile(StartS + "[^" + StartS + EndS + "]*" + EndS)
	ReStripMarkers   = regexp.MustCompile("[" + StartS + EndS + "]")
)

Internal variables.

Functions

func EndMarker

func EndMarker() []byte

EndMarker returns the end delimiter for an unsafe string.

func EscapeMarkers

func EscapeMarkers(s []byte) []byte

EscapeMarkers escapes the special delimiters from the provided byte slice.

func RedactedMarker

func RedactedMarker() []byte

RedactedMarker returns the special string used by Redact.

func StartMarker

func StartMarker() []byte

StartMarker returns the start delimiter for an unsafe string.

Types

type RedactableBytes

type RedactableBytes []byte

RedactableBytes is like RedactableString but is a byte slice.

Instances of RedactableBytes should not be constructed directly; instead use the facilities from print.go (Sprint, Sprintf) or the methods below.

func (RedactableBytes) Redact

func (s RedactableBytes) Redact() RedactableBytes

Redact replaces all occurrences of unsafe substrings by the “Redacted” marker, ‹×›.

func (RedactableBytes) SafeFormat

func (s RedactableBytes) SafeFormat(sp i.SafePrinter, _ rune)

SafeFormat formats the redactable safely.

func (RedactableBytes) StripMarkers

func (s RedactableBytes) StripMarkers() []byte

StripMarkers removes the redaction markers from the RedactableBytes. This returns an unsafe string where all safe and unsafe bits are mixed together.

func (RedactableBytes) ToString

func (s RedactableBytes) ToString() RedactableString

ToString converts the byte slice to a string.

type RedactableString

type RedactableString string

RedactableString is a string that contains a mix of safe and unsafe bits of data, but where it is known that unsafe bits are enclosed by redaction markers ‹ and ›, and occurrences of the markers inside the original data items have been escaped.

Instances of RedactableString should not be constructed directly; instead use the facilities from print.go (Sprint, Sprintf) or the methods below.

func (RedactableString) Redact

Redact replaces all occurrences of unsafe substrings by the “Redacted” marker, ‹×›. The result string is still safe.

func (RedactableString) SafeFormat

func (s RedactableString) SafeFormat(sp i.SafePrinter, _ rune)

SafeFormat formats the redactable safely.

func (RedactableString) StripMarkers

func (s RedactableString) StripMarkers() string

StripMarkers removes the redaction markers from the RedactableString. This returns an unsafe string where all safe and unsafe bits are mixed together.

func (RedactableString) ToBytes

func (s RedactableString) ToBytes() RedactableBytes

ToBytes converts the string to a byte slice.

Jump to

Keyboard shortcuts

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