This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
name.go
132 lines (113 loc) · 2.87 KB
/
name.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package schemax
/*
NewName initializes and returns a new instance of [QuotedDescriptorList].
*/
func NewName() (name QuotedDescriptorList) {
name = QuotedDescriptorList(newQDescrList(``))
name.cast().SetPresentationPolicy(name.smvStringer)
return
}
/*
Len returns the current integer length of the receiver instance.
*/
func (r QuotedDescriptorList) Len() int {
return r.len()
}
func (r QuotedDescriptorList) len() int {
return r.cast().Len()
}
/*
Push returns an error following an attempt to push name into
the receiver instance. The name value must be non-zero in
length and must be a valid RFC 4512 "descr" qualifier.
*/
func (r QuotedDescriptorList) Push(name string) error {
return r.push(name)
}
func (r QuotedDescriptorList) push(name string) (err error) {
if len(name) == 0 {
err = ErrNilInput
return
} else if !isDescriptor(name) {
err = mkerr("Invalid RFC 4512 descriptor '" + name + `'`)
return
}
r.cast().Push(name)
return
}
/*
Contains returns a Boolean value indicative of whether the input
name value was found within the receiver instance. Case-folding
is not significant in this operation.
*/
func (r QuotedDescriptorList) Contains(name string) bool {
return r.contains(name)
}
func (r QuotedDescriptorList) contains(name string) (found bool) {
for i := 0; i < r.len(); i++ {
if eq(name, r.index(i)) {
found = true
break
}
}
return
}
/*
List returns slices of string names from within the receiver.
*/
func (r QuotedDescriptorList) List() (list []string) {
for i := 0; i < r.len(); i++ {
list = append(list, r.index(i))
}
return
}
/*
IsZero returns a Boolean value indicative of a nil receiver state.
*/
func (r QuotedDescriptorList) IsZero() bool {
return r.cast().IsZero()
}
/*
String is a stringer method that returns a properly formatted
quoted descriptor list based on the number of string values
within the receiver instance.
*/
func (r QuotedDescriptorList) String() string {
return r.cast().String()
}
// smvStringer (single-or-multivalue) is the underlying
// stringer mechanism called by r.String.
//
// This method qualifies for stackage.PresentationPolicy.
func (r QuotedDescriptorList) smvStringer(_ ...any) (smv string) {
switch tv := r.len(); tv {
case 0:
break
case 1:
smv = `'` + r.index(0) + `'`
default:
var smvs []string
for i := 0; i < tv; i++ {
smvs = append(smvs, `'`+r.index(i)+`'`)
}
padchar := string(rune(32))
if !r.cast().IsPadded() {
padchar = ``
}
smv = `(` + padchar + join(smvs, ` `) + padchar + `)`
}
return
}
/*
Index returns the instance of string found within the receiver stack
instance at index N. If no instance is found at the index specified,
a zero string instance is returned.
*/
func (r QuotedDescriptorList) Index(idx int) string {
return r.index(idx)
}
func (r QuotedDescriptorList) index(idx int) (name string) {
raw, _ := r.cast().Index(idx)
name, _ = raw.(string)
return
}