-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.go
68 lines (50 loc) · 1.42 KB
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
/* Tag is a basic type describing a tag to categorize items, either as simple statement or as an expression */
/* ================================================================================ Imports */
import (
"fmt"
"strings"
)
/* ================================================================================ Public types */
type Tag struct {
Expression string
}
/* ================================================================================ Public functions */
func ParseTagEditString(tagString string) []Tag {
if len(tagString) < 1 {
return nil
}
expressions := strings.Split(tagString, ";")
validCount := 0
for i, expression := range expressions {
expressions[i] = strings.TrimSpace(expression)
if len(expressions[i]) > 0 {
validCount++
}
}
tags := make([]Tag, validCount)
i := 0
for _, expression := range expressions {
if len(expression) > 0 {
tags[i].Expression = expression
i++
}
}
return tags
}
func ComposeTagEditString(tags []Tag) string {
buffer := &strings.Builder{}
for _, tag := range tags {
fmt.Fprintf(buffer, "%s; ", tag.Expression)
}
return buffer.String()
}
/* ================================================================================ Public methods */
func (t *Tag) DisplayString() string {
before, after, found := strings.Cut(t.Expression, "=")
if(found) {
return fmt.Sprintf("%s: %s", before, after)
} else {
return before
}
}