transforms

package
v2.0.28+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package transforms provides a mechanism to define and apply string data transformations, with the transformations defined by regular expressions to match data to be transformed, and regular expression generators to specify additional or replacement data.

Index

Constants

View Source
const (
	SCOPE_ANY = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ScopedSpecNames

type ScopedSpecNames map[string][]string

ScopedSpecNames groups a list of Specs, referenced by their Spec name, with the group defined by a scope. The meaning of scope depends on the context in which the transforms are to be used.

For example, in the context of DNS request transforms, the scope is the DNS server for which a specific group of transforms is known to be effective.

The scope name "" is SCOPE_ANY, and matches any input scope name when there is no specific entry for that scope name in ScopedSpecNames.

func (ScopedSpecNames) Validate

func (scopedSpecs ScopedSpecNames) Validate(specs Specs) error

Validate checks that the ScopedSpecNames is well-formed and referenced Spec names are defined in the corresponding input specs.

type Spec

type Spec [][2]string

Spec is a transform spec. A spec is a list of individual transforms to be applied in order. Each transform is defined by two elements: a regular expression to by matched against the input; and a regular expression generator which generates new data. Subgroups from the regular expression may be specified in the regular expression generator, and are populated with the subgroup match, and in this way parts of the original matching data may be retained in the transformed data.

For example, with the transform [2]string{"([a-b])", "\\$\\ {1\\}"c}, substrings consisting of the characters 'a' and 'b' will be transformed into the same substring with a single character 'c' appended.

func (Spec) Apply

func (spec Spec) Apply(seed *prng.Seed, input string) (string, error)

Apply applies the Spec to the input string, producing the output string.

The input seed is used for all random generation. The same seed can be supplied to produce the same output, for replay.

type Specs

type Specs map[string]Spec

Specs is a set of named Specs.

func (Specs) Select

func (specs Specs) Select(scope string, scopedSpecs ScopedSpecNames) (string, Spec)

Select picks a Spec from Specs based on the input scope and scoping rules. If the input scope name is defined in scopedSpecs, that match takes precedence. Otherwise SCOPE_ANY is selected, when present.

After the scope is resolved, Select randomly selects from the matching Spec list.

Select will return "", nil when no selection can be made.

func (Specs) Validate

func (specs Specs) Validate() error

Validate checks that all entries in a set of Specs is well-formed, with valid regular expressions.

Jump to

Keyboard shortcuts

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