Create NewGenerator and checks for the generator construct

This commit is contained in:
Jason Streifling 2024-10-16 16:58:58 +02:00
parent 92d71fdbde
commit 566227773e

View File

@ -1,6 +1,10 @@
package atomfeed
import "errors"
import (
"errors"
"fmt"
"html"
)
type Generator struct {
*CommonAttributes
@ -9,10 +13,24 @@ type Generator struct {
Text string `xml:"text"`
}
func NewGenerator(text string) *Generator {
return &Generator{Text: html.UnescapeString(text)}
}
func (g *Generator) Check() error {
if g.URI != "" {
if !isValidURI(g.URI) {
return fmt.Errorf("uri attribute %v of generator not correctly formatted", g.URI)
}
}
if g.Text == "" {
return errors.New("text element of generator empty")
}
if !isCorrectlyEscaped(g.Text) {
return fmt.Errorf("text element %v of generator not correctly escaped", g.Text)
}
return nil
}