mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
extract date parser to a new file
This commit is contained in:
parent
cf5856bdf7
commit
0828d6782e
@ -1,39 +1,6 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
func firstNonEmpty(vals ...string) string {
|
||||
for _, val := range vals {
|
||||
valTrimmed := strings.TrimSpace(val)
|
||||
if len(valTrimmed) > 0 {
|
||||
return valTrimmed
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var linkRe = regexp.MustCompile(`(https?:\/\/\S+)`)
|
||||
|
||||
func plain2html(text string) string {
|
||||
text = linkRe.ReplaceAllString(text, `<a href="$1">$1</a>`)
|
||||
text = strings.ReplaceAll(text, "\n", "<br>")
|
||||
return text
|
||||
}
|
||||
|
||||
func xmlDecoder(r io.Reader) *xml.Decoder {
|
||||
decoder := xml.NewDecoder(r)
|
||||
decoder.Strict = false
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
return decoder
|
||||
}
|
||||
import "time"
|
||||
|
||||
// taken from github.com/mjibson/goread
|
||||
var dateFormats = []string{
|
35
src/parser/util.go
Normal file
35
src/parser/util.go
Normal file
@ -0,0 +1,35 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
func firstNonEmpty(vals ...string) string {
|
||||
for _, val := range vals {
|
||||
valTrimmed := strings.TrimSpace(val)
|
||||
if len(valTrimmed) > 0 {
|
||||
return valTrimmed
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var linkRe = regexp.MustCompile(`(https?:\/\/\S+)`)
|
||||
|
||||
func plain2html(text string) string {
|
||||
text = linkRe.ReplaceAllString(text, `<a href="$1">$1</a>`)
|
||||
text = strings.ReplaceAll(text, "\n", "<br>")
|
||||
return text
|
||||
}
|
||||
|
||||
func xmlDecoder(r io.Reader) *xml.Decoder {
|
||||
decoder := xml.NewDecoder(r)
|
||||
decoder.Strict = false
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
return decoder
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user