Documentation ¶
Overview ¶
Package vnameutil provides utilities for generating consistent VNames from common path-like values (e.g., filenames, import paths).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Rule ¶
type Rule struct { *regexp.Regexp // A pattern to match against an input string *spb.VName // A template to populate with matches from the input }
A Rule associates a regular expression pattern with a VName template. A Rule can be applied to a string to produce a VName.
func ConvertRule ¶ added in v0.0.31
func ConvertRule(r *spb.VNameRewriteRule) (Rule, error)
ConvertRule compiles a VNameRewriteRule proto into a Rule that can be applied to strings.
func (Rule) Apply ¶
Apply reports whether input matches the regexp associated with r. If so, it returns a VName whose fields have values taken from r.VName, with submatches populated from the input string.
Submatch replacement is done using regexp.ExpandString, so the same syntax is supported for specifying replacements.
type Rules ¶
type Rules []Rule
Rules are an ordered set of rewriting rules. Applying a group of rules tries each rule in sequence, and returns the result of the first one that matches.
func LoadRules ¶ added in v0.0.31
LoadRules loads and parses the vname mapping rules in path. If path == "", this returns nil without error (no rules).
func ParseRules ¶
ParseRules reads Rules data from a byte array.
func ReadRules ¶ added in v0.0.31
ReadRules parses Rules from JSON-encoded data in the following format:
[ { "pattern": "re2_regex_pattern", "vname": { "corpus": "corpus_template", "root": "root_template", "path": "path_template" } }, ... ]
Each pattern is an RE2 regexp pattern. Patterns are implicitly anchored at both ends. The template strings may contain markers of the form @n@, that will be replaced by the n'th regexp group on a successful input match.