Added Delete methods for slice elements to common attributes, entry, feed, person and source

This commit is contained in:
2024-10-20 10:49:29 +02:00
parent e2986e70b1
commit e0384904b4
5 changed files with 292 additions and 62 deletions

View File

@@ -17,7 +17,7 @@ func newCommonAttributes() *CommonAttributes {
return new(CommonAttributes)
}
// AddAttribute adds the Attribute to the CommonAttributes.
// AddAttribute adds the attribute to the CommonAttributes.
func (c *CommonAttributes) AddAttribute(name, value string) {
if c.UndefinedAttributes == nil {
c.UndefinedAttributes = make([]*xml.Attr, 1)
@@ -27,6 +27,18 @@ func (c *CommonAttributes) AddAttribute(name, value string) {
}
}
// DeleteAttribute deletes the attribute from the CommonAttributes. It return an
// error.
func (c *CommonAttributes) DeleteAttribute(id int) error {
length := len(c.UndefinedAttributes)
if id > length {
return fmt.Errorf("error deleting undefined attribute from common attributes %v: id %v out of range %v", c, id, length)
}
c.UndefinedAttributes = append(c.UndefinedAttributes[:id], c.UndefinedAttributes[id+1:]...)
return nil
}
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
// returns an error.
func (c *CommonAttributes) Check() error {