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 ¶
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 )
var ( // All represents the string instruction set that contains all alpha-numeric // 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} )
var Rand = &random{s: util.Rand}
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 instructsions 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 by 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 cannotate usage, and 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 ¶
Match returns a valid Regexp struct that is guaranteed to match any string generated by the Matcher's 'String' function.
func (Matcher) MatchEx ¶
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 ¶
Raw returns the raw string value of this Matcher without preforming any replacements.