text

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Overview

Package text is a simple package for generating random string values with complex requirements and regular expressions.

This package exposes a 'Rand' struct that can be used to generate multiple types of string values.

The other exported types allow for generation of mutable expressions that can be used to generate matching regular expression values. These work well with any package that works with stringers, such as the "wc2" package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// MatchAny is a Matcher that can be used to match any string or byte array.
	MatchAny anyRegexp
	// MatchNone is a Matcher that can be used to NOT match any string or byte
	// array.
	MatchNone falseRegexp
)
View Source
var (
	// All represents the string instruction set that contains all alphanumeric
	// characters.
	All set = [2]byte{0, 62}
	// Upper represents the string instruction set that contains only uppercase
	// non-numeric characters.
	Upper set = [2]byte{26, 52}
	// Lower represents the string instruction set that contains only lowercase
	// non-numeric characters.
	Lower set = [2]byte{0, 26}
	// Numbers represents the string instruction set that contains only numeric
	// characters.
	Numbers set = [2]byte{52, 62}
	// Characters represents the string instruction set that contains mixed case
	// non-numeric characters.
	Characters set = [2]byte{0, 52}
)
View Source
var Rand = random{/* contains filtered or unexported fields */}

Rand is the custom Random number generator, based on the 'util.Rand' choice. This random can be used to create custom random string values.

Functions

This section is empty.

Types

type Matcher

type Matcher string

Matcher is an alias of a string that can contain specific variable instructions to be replaced when calling the 'String' function. This alias provides the 'Match' function, which returns a Regexp struct that will match any value generated.

Matcher Verb Guide

<N> indicates a non-negative number value that is REQUIRED. [N] indicated a non-negative number value that is OPTIONAL.

  • If omitted, a random positive 8 to 32bit value will be used.

If the number is followed bfy a 'f', this will FORCE the count and will use it directly instead of a range to N. Otherwise, a [1, N] (inclusive) value will be generated to be used instead.

In both cases, the '<', '[', ']', and '>' are only used to indicate usage, and are not actually used in the string value.

| Verb   | Description                                         | RegEx            |
| ------ | --------------------------------------------------- | ---------------- |
| %<N>n  | 1 to N count of random single-digit numbers         | [0-9]{1,N}       |
| %<N>fn | N count of random single-digit numbers              | [0-9]{N}         |
| %<N>c  | 1 to N count of random ASCII non-number characters  | [a-zA-Z]{1,N}    |
| %<N>fc | N count of random ASCII non-number characters       | [a-zA-Z]{N}      |
| %<N>u  | 1 to N count of random ASCII uppercase characters   | [A-Z]{1,N}       |
| %<N>fu | N count of random ASCII uppercase characters        | [A-Z]{N}         |
| %<N>l  | 1 to N count of random ASCII lowercase characters   | [a-z]{1,N}       |
| %<N>fl | N count of random ASCII lowercase characters        | [a-z]{n}         |
| %s     | Random 1 to 256 count of random ASCII characters    | ([a-zA-Z0-9]+)   |
| %[N]s  | 1 to N (or random) count of random ASCII characters | [a-zA-Z0-9]{1,N} |
| %<N>fs | N count of random ASCII characters                  | [a-zA-Z0-9]{N}   |
| %d     | String literal number 0 to 4,294,967,296            | ([0-9]+)         |
| %<N>d  | String literal number 0 to N                        | ([0-9]+)         |
| %<N>fd | String literal number N                             | ([0-9]+)         |
| %h     | Hex string literal number 0 to 4,294,967,296        | ([a-fA-F0-9]+)   |
| %<N>h  | Hex string literal number 0 to N                    | ([a-fA-F0-9]+)   |
| %<N>fh | Hex string literal number N                         | ([a-fA-F0-9]+)   |

All other values are ignored and directly added to the resulting string value.

func (Matcher) Match

func (s Matcher) Match() Regexp

Match returns a valid Regexp struct that is guaranteed to match any string generated by the Matcher's 'String' function.

func (Matcher) MatchEx

func (s Matcher) MatchEx(o bool) Regexp

MatchEx returns a valid Regexp struct that is guaranteed to match any string generated by the Matcher's 'String' function. MatchEx returns an inverse matcher if the bool is false.

func (Matcher) Raw

func (s Matcher) Raw() string

Raw returns the raw string value of this Matcher without preforming any replacements.

func (Matcher) String

func (s Matcher) String() string

String parses this MatchString value and will preform any replacements and fill any variables contained.

func (Matcher) UnMatch

func (s Matcher) UnMatch() Regexp

UnMatch returns a valid Regexp struct that is guaranteed to not match any string generated by the Matcher's 'String' function.

type Regexp

type Regexp interface {
	String() string
	Match([]byte) bool
	MatchString(string) bool
}

Regexp is a compatibility interface that is used to allow for UnMatch values to be used lacking the ability of RE2 used in Golang to do negative lookahead.

type String

type String string

String is a wrapper for strings to support the Stringer interface.

func (String) String

func (s String) String() string

String returns the string value of itself.

Jump to

Keyboard shortcuts

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