2024-10-13 17:19:40 +02:00
|
|
|
package atomfeed
|
|
|
|
|
2024-10-16 16:58:58 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"html"
|
|
|
|
)
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
type Generator struct {
|
|
|
|
*CommonAttributes
|
2024-10-16 17:33:25 +02:00
|
|
|
URI IRI `xml:"uri,attr,omitempty"`
|
2024-10-13 17:19:40 +02:00
|
|
|
Version string `xml:"version,attr,omitempty"`
|
|
|
|
Text string `xml:"text"`
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// NewGenerator creates a new Generator. It returns a *Generator.
|
2024-10-16 16:58:58 +02:00
|
|
|
func NewGenerator(text string) *Generator {
|
|
|
|
return &Generator{Text: html.UnescapeString(text)}
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the Generator for incompatibilities with RFC4287. It returns an
|
|
|
|
// error.
|
2024-10-13 17:19:40 +02:00
|
|
|
func (g *Generator) Check() error {
|
2024-10-16 16:58:58 +02:00
|
|
|
if g.URI != "" {
|
2024-10-16 17:33:25 +02:00
|
|
|
if !isValidIRI(g.URI) {
|
2024-10-16 16:58:58 +02:00
|
|
|
return fmt.Errorf("uri attribute %v of generator not correctly formatted", g.URI)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
if g.Text == "" {
|
|
|
|
return errors.New("text element of generator empty")
|
|
|
|
}
|
|
|
|
|
2024-10-16 16:58:58 +02:00
|
|
|
if !isCorrectlyEscaped(g.Text) {
|
|
|
|
return fmt.Errorf("text element %v of generator not correctly escaped", g.Text)
|
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
return nil
|
|
|
|
}
|