Дополнение в атрибутах

This commit is contained in:
Anatoly Prohacky 2022-08-13 16:50:20 +10:00
parent 64cf65f07e
commit 758979f11b

View File

@ -1,21 +1,25 @@
package atr package atr
import "strings"
type Atr string type Atr string
const sep Atr = ","
// New Atr // New Atr
func New(a string) Atr { func New(a string) Atr {
return Atr(a) return Atr(a)
} }
//Glue slice Atr to Atr //Glue slice Atr to Atr
func Glue(atr []Atr) Atr { func Glue(atr ...Atr) Atr {
var endatr Atr var endatr Atr
lenatr := len(atr) lenatr := len(atr)
for _, a0 := range atr { for _, a0 := range atr {
if a0 != "" { if a0 != "" {
endatr = endatr + a0 endatr = endatr + a0
if lenatr > 1 { if lenatr > 1 {
endatr = endatr + "," endatr = endatr + sep
} }
} }
lenatr-- lenatr--
@ -23,3 +27,13 @@ func Glue(atr []Atr) Atr {
return endatr return endatr
} }
//Split Atr to slice Atr
func Split(a Atr) []Atr {
var endatr []Atr
split := strings.Split(string(a), string(sep))
for _, s := range split {
endatr = append(endatr, Atr(s))
}
return endatr
}