~shulhan/asciidoctor-go

ref: v0.1.0 asciidoctor-go/attribute_class.go -rw-r--r-- 755 bytes
4c1ded16Shulhan Release asciidoctor-go v0.1.0 (2021-03-06) 4 months ago
                                                                                
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
// Copyright 2020, Shulhan <ms@kilabit.info>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package asciidoctor

import (
	"strings"

	libstrings "github.com/shuLhan/share/lib/strings"
)

type attributeClass []string

func (aclass *attributeClass) add(c string) {
	(*aclass) = libstrings.AppendUniq(*aclass, c)
}

func (aclass *attributeClass) replace(old, new string) {
	for x, v := range *aclass {
		if v == old {
			(*aclass)[x] = new
			return
		}
	}
	// Add class if not found.
	aclass.add(new)
}

//
// String concat all the attribute class into string separated by single
// space.
//
func (aclass attributeClass) String() string {
	return strings.Join(aclass, " ")
}