diff options
Diffstat (limited to 'document_attribute.go')
| -rw-r--r-- | document_attribute.go | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/document_attribute.go b/document_attribute.go index 31dbb50..357a0e0 100644 --- a/document_attribute.go +++ b/document_attribute.go @@ -56,27 +56,36 @@ const ( // DocumentAttribute contains the mapping of global attribute keys in the // headers with its value. -type DocumentAttribute map[string]string +type DocumentAttribute struct { + Entry map[string]string +} func newDocumentAttribute() DocumentAttribute { return DocumentAttribute{ - DocAttrGenerator: `asciidoctor-go ` + Version, - docAttrLastUpdateLabel: `Last updated`, - docAttrLastUpdateValue: ``, - docAttrSectIDs: ``, - docAttrShowTitle: ``, - docAttrTableCaption: ``, - docAttrVersionLabel: ``, + Entry: map[string]string{ + DocAttrGenerator: `asciidoctor-go ` + Version, + docAttrLastUpdateLabel: `Last updated`, + docAttrLastUpdateValue: ``, + docAttrSectIDs: ``, + docAttrShowTitle: ``, + docAttrTableCaption: ``, + docAttrVersionLabel: ``, + }, } } -func (entry *DocumentAttribute) apply(key, val string) { - switch { - case key[0] == '!': - delete(*entry, strings.TrimSpace(key[1:])) - case key[len(key)-1] == '!': - delete(*entry, strings.TrimSpace(key[:len(key)-1])) - default: - (*entry)[key] = val +func (docAttr *DocumentAttribute) apply(key, val string) { + if key[0] == '!' { + key = strings.TrimSpace(key[1:]) + delete(docAttr.Entry, key) + return + } + var n = len(key) + if key[n-1] == '!' { + key = strings.TrimSpace(key[:n-1]) + delete(docAttr.Entry, key) + return } + + docAttr.Entry[key] = val } |
