brackets

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func XMLEscape

func XMLEscape(s string) string

XMLEscape returns properly escaped XML equivalent of the provided string

Types

type Attributes

type Attributes map[string]string

Attributes represents bracket attributes

func (Attributes) Clone

func (am Attributes) Clone() Attributes

Clone creates a deep copy of a map

func (Attributes) Size

func (am Attributes) Size() (size int)

Size calculates the total size in bytes of all keys + values

func (Attributes) String

func (am Attributes) String() string

type Brackets

type Brackets struct {
	// contains filtered or unexported fields
}

Brackets is a simple xml-ish structure builder

func New

func New() *Brackets

New - Brackets constructor

func (*Brackets) Add

func (b *Brackets) Add(name string, attrs ...Attributes) *Brackets

Add adds a self-closing element

func (*Brackets) Append

func (b *Brackets) Append(other *Brackets) *Brackets

Append adds all elements from another Brackets instance

func (*Brackets) Close

func (b *Brackets) Close() *Brackets

Close closes the current element. If there are no children (elements or text), the current element will be self-closed. Otherwise, a matching close-element will be added.

func (*Brackets) CloseAll

func (b *Brackets) CloseAll() *Brackets

CloseAll closes all elements to get a complete, matched structure.

func (*Brackets) Current

func (b *Brackets) Current() *Element

Current returns a pointer to the currently open element, or nil if there is none.

func (*Brackets) First added in v0.3.0

func (b *Brackets) First() *Element

First returns the first element of the underlying list of elements.

func (*Brackets) Last

func (b *Brackets) Last() *Element

Last returns a pointer to the most recently added element, or nil if there is none.

func (*Brackets) Open

func (b *Brackets) Open(name string, attrs ...Attributes) *Brackets

Open adds a new opening element with optional attributes.

func (*Brackets) String

func (b *Brackets) String() string

func (*Brackets) Text

func (b *Brackets) Text(txt string) *Brackets

Text adds text content to the current element. Note that the text is not automatically XML-escaped. Use the XMLEscape function if that is needed.

type Element

type Element struct {
	// contains filtered or unexported fields
}

Element represents an xml element

func (*Element) Attributes

func (e *Element) Attributes() Attributes

Attributes returns a copy of the element attributes

func (*Element) Name

func (e *Element) Name() string

Name returns the element name

func (*Element) SetAttribute

func (e *Element) SetAttribute(key, value string)

SetAttribute resets an attribute to a new value

func (*Element) String

func (e *Element) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL