decode

package
v0.0.0-...-7fb543b Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2017 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeEncode

func DecodeEncode(buf string, encode bool, codec string) (out string, codecUsed string, err error)

DecodeEncode takes an input string `buf` and decodes/encodes it (depending on the `encode` parameter) with the given `codec`. It returns the encoded/decoded string or an error if the process failed.

func IsPrint

func IsPrint(decoded string) bool

IsPrint checks if a decoded string is a valid utf string

func MainStandalone

func MainStandalone(args ...string)

MainStandalone parses its own flag and it is the funcion to be run when using `wapty decode`. This behaves as a main and expects the "decode" parameter to be removed from os.Args.

Types

type Base16

type Base16 struct {
	// contains filtered or unexported fields
}

Base16 takes a decoder and an input string

func (*Base16) Check

func (b *Base16) Check() (acceptability float64)

Check returns the percentage of valid b16 characters in the input string

func (*Base16) Decode

func (b *Base16) Decode() (output string)

Decode a valid b16 string

func (*Base16) Encode

func (b *Base16) Encode() (output string)

Encode a string into b16

func (*Base16) Name

func (b *Base16) Name() string

Name returns the name of the codec

type Base32

type Base32 struct {
	// contains filtered or unexported fields
}

Base32 takes a decoder and an input string

func (*Base32) Check

func (b *Base32) Check() (acceptability float64)

Check returns the percentage of valid b32 characters in the input string

func (*Base32) Decode

func (b *Base32) Decode() (output string)

Decode a valid b32 string

func (*Base32) Encode

func (b *Base32) Encode() (output string)

Encode a string into b32

func (*Base32) Name

func (b *Base32) Name() string

Name returns the name of the codec

type Base64

type Base64 struct {
	// contains filtered or unexported fields
}

Base64 takes a decoder and an input string

func (*Base64) Check

func (b *Base64) Check() (acceptability float64)

Check returns the percentage of valid b16 characters in the input string

func (*Base64) Decode

func (b *Base64) Decode() (output string)

Decode a valid b64 string

func (*Base64) Encode

func (b *Base64) Encode() (output string)

Encode a string into b64 with StdEncodig set

func (*Base64) Name

func (b *Base64) Name() string

Name returns the name of the codec

type Checker

type Checker interface {
	Check() (acceptability float64)
}

Checker returns a metric to determine how likely it is for the given string to be a valid value for the specified Checker Type. The likelihood always ranges between 0 and 1

type CodecC

type CodecC interface {
	Decoder
	Encoder
	Checker
	Name() string
}

CodecC creates an interface of interfaces usable by other codecs

func NewB16CodecC

func NewB16CodecC(in string) CodecC

NewB16CodecC state machine to smartly decode a string with invalid chars nolint: gocyclo

func NewB32CodecC

func NewB32CodecC(in string) CodecC

NewB32CodecC state machine to smartly decode a string with invalid chars nolint: gocyclo

func NewB64CodecC

func NewB64CodecC(in string) CodecC

NewB64CodecC state machine to smartly decode a string with invalid chars and different variants nolint: gocyclo

func NewURLCodecC

func NewURLCodecC(in string) CodecC

func SmartDecode

func SmartDecode(input string) (c CodecC)

SmartDecode loops through the available CodecCs and determine which one is the best one to use

type Decoder

type Decoder interface {
	Decode() (output string)
}

Decoder decodes the string and returns a decoded value that tries to skip invalid input and to decode as much as possible. Returns if the decoded string can be printed as valid unicode.

type Encoder

type Encoder interface {
	Encode() (output string)
}

Encoder encodes the string

type Pos

type Pos int

Pos is an integer that define a position inside a string

type URL

type URL struct {
	// contains filtered or unexported fields
}

URL takes an input string

func (*URL) Check

func (b *URL) Check() (acceptability float64)

Check returns the percentage of valid url characters in the input string

func (*URL) Decode

func (b *URL) Decode() (output string)

Decode a valid url encoded string

func (*URL) Encode

func (b *URL) Encode() (output string)

Encode a string to url encode

func (*URL) Name

func (b *URL) Name() string

Name returns the name of the codec

Jump to

Keyboard shortcuts

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