unregex

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxCount    = 10
	DefaultMinCount    = 0
	DefaultAnyCharsMax = utf8.MaxRune
	DefaultAnyCharsMin = rune(0)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Unregexer

type Unregexer struct {
	// MinReps is the minimum number of times a repeated regex should be
	// generated when deriving a string. This applies to all repetition
	// operators like `*`, `+`, and `{n,m}`. If an operator specifies a minimum
	// lower than MinReps, MinReps is used as the minimum repetitions for the
	// operand during derivation.
	MinReps int

	// MaxReps is the minimum number of times a repeated regex should be
	// generated when deriving a string. This applies to all repetition
	// operators like `*`, `+`, and `{n,m}`. If an operator specifies a maximum
	// higher than MaxReps, MaxReps is used as the maximum repetitions for the
	// operand during derivation.
	MaxReps int

	// AnyCharsMax specifies the maximum value (inclusive) of the range of
	// characters that is selected from when deriving a string for a match
	// operator that specifies any character (dot operator) or any character
	// except for some set of chars (negated character class).
	AnyCharsMax rune

	// AnyCharsMin specifies the minimum value (inclusive) of the range of
	// characters that is selected from when deriving a string for a match
	// operator that specifies any character (dot operator) or any character
	// except for some set of chars (negated character class).
	AnyCharsMin rune
	// contains filtered or unexported fields
}

Unregexer derives strings from a regex. It uses a random number generator that must be explicitly seeded.

Do not use Unregexer directly. Instead, use New() to create one.

Unregexer uses an 'AnyChars' set to determine which ones are allowed to be generated for 'any' operators, such as the dot operator. This also includes negated character classes that can be detected. Note that due to how regex intermediate representation works in Go, negation is not noted on a compiled regex. Instead, Unregexer considers a character class of any size that includes value utf8.MaxRune or greater to be negated. As a consequence, it will treat any non-negated character class that explicitly includes utf8.MaxRune or greater as negated, and any negated character class that explicitly excludes utf8.MaxRune or greater as non-negated.

The range of the AnyChars set can be changed by setting AnyCharsMin and AnyCharsMax.

func New

func New(regex string) (*Unregexer, error)

func (*Unregexer) Derive

func (u *Unregexer) Derive() string

func (*Unregexer) Seed

func (u *Unregexer) Seed(val int64)

func (*Unregexer) SeedTime

func (u *Unregexer) SeedTime()

Jump to

Keyboard shortcuts

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