tags

package
v0.0.0-...-b0fc717 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WildcardMatch

func WildcardMatch(wildcard, tag string) bool

Types

type DiffMembership

type DiffMembership int
const AddsTag DiffMembership = 1
const NotPresent DiffMembership = 0
const RemovesTag DiffMembership = -1
const ResetsTag DiffMembership = 0

type StringDiff

type StringDiff struct {
	AddList    map[string]bool `json:"add"`
	RemoveList map[string]bool `json:"remove"`
}

func StringDiffFromArray

func StringDiffFromArray(tag_diff []string) StringDiff

StringDiffFromArray (singular) builds a new StringDiff using the specified tag list. all of the *single argument* constructor functions for StringDiff and TagDiff fkow through this function. It's not simply implemented in terms of Apply because that function is designed to interpret tags starting with = as "reset" tags, i.e. remove them from both lists, and because of that it also treats + as a special prefix to enable adding natural tags beginning with =. All in all, it creates a bit of a mess, so it's useful to separate that logic (which is more suitable for ongoing mutations of existing objects) from this logic, which is useful for constructing new objects, most typically from API-compatible string exports of old ones.

func StringDiffFromArrays

func StringDiffFromArrays(add_tags, remove_tags []string) StringDiff

StringDiffFromArrays builds a new StringDiff using the specified add and remove tags. Ultimately, all of the other constructor functions for StringDiff and TagDiff flow through this function.

func StringDiffFromStringWithDelimiter

func StringDiffFromStringWithDelimiter(tag_diff, delimiter string) StringDiff

func StringDiffFromStringsWithDelimiter

func StringDiffFromStringsWithDelimiter(add_tags, remove_tags, delimiter string) StringDiff

func (*StringDiff) Add

func (this *StringDiff) Add(tag string)

func (StringDiff) AddedSet

func (this StringDiff) AddedSet() StringSet

func (*StringDiff) Apply

func (this *StringDiff) Apply(tag string)

func (*StringDiff) ApplyArray

func (this *StringDiff) ApplyArray(tag_diff []string)

func (*StringDiff) ApplyArrays

func (this *StringDiff) ApplyArrays(add_tags, remove_tags, reset_tags []string)

func (*StringDiff) ApplyStringWithDelimiter

func (this *StringDiff) ApplyStringWithDelimiter(tag_diff, delimiter string)

func (*StringDiff) ApplyStringsWithDelimiter

func (this *StringDiff) ApplyStringsWithDelimiter(add_tags, remove_tags, reset_tags, delimiter string)

func (StringDiff) Array

func (this StringDiff) Array() []string

func (*StringDiff) Clear

func (this *StringDiff) Clear()

func (StringDiff) Difference

func (this StringDiff) Difference(other StringDiff) StringDiff

func (StringDiff) Equal

func (this StringDiff) Equal(other StringDiff) bool

func (StringDiff) Invert

func (this StringDiff) Invert() StringDiff

func (StringDiff) IsZero

func (this StringDiff) IsZero() bool

func (StringDiff) Len

func (this StringDiff) Len() int

func (*StringDiff) Remove

func (this *StringDiff) Remove(tag string)

func (StringDiff) RemovedSet

func (this StringDiff) RemovedSet() StringSet

func (*StringDiff) Reset

func (this *StringDiff) Reset(tag string)

func (*StringDiff) Status

func (this *StringDiff) Status(tag string) DiffMembership

func (StringDiff) StringWithDelimiter

func (this StringDiff) StringWithDelimiter(delimiter string) string

func (StringDiff) Union

func (this StringDiff) Union(other StringDiff) StringDiff

type StringDiffArray

type StringDiffArray []StringDiff

func (StringDiffArray) Flatten

func (this StringDiffArray) Flatten() StringDiff

type StringSet

type StringSet struct {
	Data map[string]bool
}

func (*StringSet) Apply

func (this *StringSet) Apply(t string)

apply a single string. accepts strings prefixed with -, which negates. when negating, accepts simple asterisk wildcards to match any number of characters (as a trivial example, '-*' unsets all matches)

func (*StringSet) ApplyArray

func (this *StringSet) ApplyArray(tags []string)

applies each tag in an array. accepts tags prefixed with -.

func (*StringSet) ApplyDiff

func (this *StringSet) ApplyDiff(diff StringDiff)

apply a diff to the tag set.

func (*StringSet) ApplyStringWithDelimiter

func (this *StringSet) ApplyStringWithDelimiter(tags, delim string)

applies each token in a string with specified delimiter. accepts strings prefixed with -.

func (*StringSet) Clear

func (this *StringSet) Clear(t string)

unset a string. does not accept prefixed strings.

func (StringSet) Clone

func (this StringSet) Clone() StringSet

func (StringSet) Equal

func (this StringSet) Equal(other StringSet) bool

func (StringSet) Len

func (this StringSet) Len() int

Counts the number of strings.

func (*StringSet) Merge

func (this *StringSet) Merge(other StringSet)

func (*StringSet) Reset

func (this *StringSet) Reset()

Clears all strings.

func (*StringSet) Set

func (this *StringSet) Set(t string)

set a string. does not accept prefixed strings.

func (*StringSet) Status

func (this *StringSet) Status(tag string) DiffMembership

checks to see if a specific tag is set. does not accept prefixed tags.

func (StringSet) StringWithDelimiter

func (this StringSet) StringWithDelimiter(delim string) string

Emits the string set as a single string with the specified delimiter.

func (*StringSet) ToggleArray

func (this *StringSet) ToggleArray(tags []string)

toggles each tag in an array, deselecting them if they are currently selected and vice versa. accepts tags prefixed with either + or -, which overrides toggling behavior (the prefix always signals the end state)

func (*StringSet) ToggleStringWithDelimiter

func (this *StringSet) ToggleStringWithDelimiter(tags, delim string)

toggles each tag in an array, deselecting them if they are currently selected and vice versa. accepts tags prefixed with either + or -, which overrides toggling behavior (the prefix always signals the end state)

type TagDiff

type TagDiff struct {
	StringDiff
}

This represents a diff to be applied to a tag set. It is specialized for string-delimited tags. Tags can, using some functions, be prefixed with +, -, or = to override default behaviors, check function docs to see where this is allowed.

TagDiff embeds StringDiff, and thus provides many of the same functions which are integral to its usage, and are documented by StringDiff.

func TagDiffFromArray

func TagDiffFromArray(tag_diff []string) TagDiff

This is the same as TagDiffFromString, except that you specify an array of pre-split tags.

func TagDiffFromArrays

func TagDiffFromArrays(add_tags, remove_tags []string) TagDiff

This is the same as TagDiffFromStrings, except that you specify arrays of pre-split tags.

func TagDiffFromString

func TagDiffFromString(tag_diff string) TagDiff

TagDiffFromString is the reverse operation of APIString. It is unambiguous for any API-legal string. Its argument is a string consisting of tags delimited by spaces, with the following prefixes: - to denote removal no prefix to denote addition (this is the default)

func TagDiffFromStringWithDelimiter

func TagDiffFromStringWithDelimiter(tag_diff, delimiter string) TagDiff

This is the same as TagDiffFromString, except that you may specify the delimiter.

func TagDiffFromStrings

func TagDiffFromStrings(add_tags, remove_tags string) TagDiff

TagDiffFromStrings takes a list of tags to add and a list of tags to remove, both delimited by spaces, and builds a TagDiff as though each tag in the add list was passed to Add, and each tag in the remove list passed to Remove. No prefixes are permitted, tags will be passed verbatim (and if they are present, it may be possible to build a TagDiff which is not API-legal)

func TagDiffFromStringsWithDelimiter

func TagDiffFromStringsWithDelimiter(add_tags, remove_tags, delimiter string) TagDiff

This is the same as TagDiffFromStrings, except that you may specify the delimiter.

func (TagDiff) APIString

func (this TagDiff) APIString() string

Builds an API compatible representation of the tag difference. Substrings are ordered first (adds, removes), then alphabetically. Removes are prefixed by a minus sign. Adds are unprefixed, and no prefix is permitted.

func (TagDiff) AddedSet

func (this TagDiff) AddedSet() TagSet

AddedSet produces an ALIAS to the tags added by this TagDiff. Changes made to one will reflect upon the other.

func (*TagDiff) ApplyString

func (this *TagDiff) ApplyString(tag_diff string)

ApplyString delimits the provided string by spaces and applies each tag in it. Tags can be prefixed: + forces addition (this is the default if a prefix isn't specified) - forces removal = forces reset (undoing a previous add or remove)

func (*TagDiff) ApplyStrings

func (this *TagDiff) ApplyStrings(add_tags, remove_tags, reset_tags string)

ApplyStrings takes three strings, representing tags to add, remove, and reset. Each string is delimited by spaces and each tag in it is applied. Prefixes are not allowed in this function, if they are present they will be included literally (this is not usually the desired result).

func (TagDiff) Difference

func (this TagDiff) Difference(other TagDiff) TagDiff

Difference yields a TagDiff such that every tag added or removed by `this` will be processed UNLESS that tag is to be added or removed by `other`, in which case the opposite will occur. Tags are added and removed by `this` first, and then by `other` second (in case the two inputs try to both add or remove the same tag).

func (TagDiff) Equal

func (this TagDiff) Equal(other TagDiff) bool

Compares a TagDiff to another. The two are only equal if they both add the same set of new tags, and remove the same set of existing tags.

func (TagDiff) Invert

func (this TagDiff) Invert() TagDiff

Invert yields a TagDiff with its add and remove sets swapped. In the case where a TagDiff applies perfectly to a TagSet (i.e. every tag in its add list was absent and added, and in its remove list, present and removed), Applying that tag diff's Invert() value will undo the change. (If that precondition is not true, it's a little more complicated, be careful)

func (TagDiff) RemovedSet

func (this TagDiff) RemovedSet() TagSet

RemovedSet produces an ALIAS to the tags removed by this TagDiff. Changes made to one will reflect upon the other.

func (TagDiff) String

func (this TagDiff) String() string

Produces a human readable representation of this TagDiff object.

func (TagDiff) Union

func (this TagDiff) Union(other TagDiff) TagDiff

Union yields a TagDiff which adds every tag added by either of its two inputs, and likewise with tags removed. Tags are added and removed by `this` first, and by `other` second (in case the two inputs try to both add remove the same tag).

type TagDiffArray

type TagDiffArray []TagDiff

This represents a list of diffs, applied sequentially.

func (TagDiffArray) Flatten

func (this TagDiffArray) Flatten() TagDiff

Flatten sequentially applies every operation from a TagDiffArray as though calling Union on them over and over, starting with the first.

type TagSet

type TagSet struct {
	StringSet
}

func (*TagSet) ApplyDiff

func (this *TagSet) ApplyDiff(diff TagDiff)

apply a tag diff to the tag set.

func (*TagSet) ApplyString

func (this *TagSet) ApplyString(tags string)

func (TagSet) Clone

func (this TagSet) Clone() TagSet

func (TagSet) Equal

func (this TagSet) Equal(other TagSet) bool

func (*TagSet) Merge

func (this *TagSet) Merge(other TagSet)

func (TagSet) String

func (this TagSet) String() string

func (*TagSet) ToggleString

func (this *TagSet) ToggleString(tags string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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