regen

package module
v0.0.0-...-e40affd Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: BSD-2-Clause Imports: 4 Imported by: 0

README

GoDoc

This is a fork of https://github.com/nilium/regen.

There are some significant changes from the original code, however:

  • Converted from binary release to a library, exposing the GenString function for reuse.
  • Switched from crypto/rand to just using math/rand by default.
  • Added an option to control of the randomness (using a function whose behavior is similar to rand.Int63n).

Documentation

Overview

Package regen is a tool to parse and generate random strings from regular expressions.

This is a fork of github.com/nilium/regen.

It provides a function to generate string from regular expressions.

regen works by parsing a regular expression and walking its op tree. It is currently not guaranteed to produce entirely accurate results, but will at least try.

Limitations from upstream:

  • Currently, word boundaries are not supported (until I decide how best to randomly insert a word boundary character).
  • Using a word boundary op (\b or \B) will currently cause regen to panic.
  • In addition, line endings are also poorly supported right now and EOT markers are treated as the end of string generation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenString

func GenString(w *bytes.Buffer, rx *syntax.Regexp, options ...Option) error

GenString writes a response that should, ideally, be a match for rx to w, and proceeds to do the same for its sub-expressions where applicable. Returns io.EOF if it encounters OpEndText. This may not be entirely correct behavior for OpEndText handling. Otherwise, returns nil.

func RandSrc

func RandSrc(randInt63n func(n int64) int64) func(*Options)

RandSrc modifies GenString, such that we use a different function to generate random number. This function will affect number of repetitions as well as the exact character used. Given the input n, randInt63n must return a number in [0, n).

Types

type Option

type Option func(*Options)

Option allow us to modify the behavior of GenString.

type Options

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

Jump to

Keyboard shortcuts

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